September 2017
Beginner
402 pages
9h 52m
English
Perl 6 offers great power, allowing you to create new character classes using operations over sets. These are—+ or | for union, - for difference, & for intersection, and ^ for the XOR operation. Additionally, character classes can be negated with either - or !.
Let us look at examples. First, create the joined class that matches with both lowercase letters and digits:
for <a A 3> -> $char { say "$char is a lowercase letter or a digit" if $char ~~ / <:Ll + :Nd> /;}
This program print matches for the characters a and 3. The capital A does not match because it is neither a lowercase letter nor a digit.
In another example, we reinvent uppercase letters by subtracting lowercase letters from the set of all letters: ...
Read now
Unlock full access