September 2017
Beginner
402 pages
9h 52m
English
These three operators create junctions. We have already seen junctions in the simplest form of having multiple values in the save variable at the same time:
my $odd = 1 | 3 | 5 | 7 | 9;my $value = 5;say 'Value is odd' if $value == $odd;
The code prints Value is odd, as the value in the $value variable is one of the values of the $odd junction. The | operator creates a so-called any junction.
The & operator creates an all junction, where all the values must be non-empty. Consider the following code snippet:
my $a = 3;my $b = 4;my $both = $a & $b;say 'ok' if $both; # ok
Finally, the ^ operator creates a one junction, where only one of the operands must be evaluated as true. Considering the following code snippet:
my $c = ...
Read now
Unlock full access