In Operators§
See primary documentation in context for infix ff
sub infix:<ff>(Mu , Mu )
Also called the flipflop operator, compares both arguments to $_
(that is, $_ ~~ $a
and $_ ~~ $b
). Evaluates to False
until the left-hand smartmatch is True
, at which point it evaluates to True
until the right-hand smartmatch is True
.
In effect, the left-hand argument is the "start" condition and the right-hand is the "stop" condition. This construct is typically used to pick up only a certain section of lines. For example:
my =my = gather for .lines# this will print four lines, starting with "=begin code" and ending with# "=end code"say .join("\n");
After matching the start condition, the operator will then match the same $_
to the stop condition and act accordingly if successful. In this example, only the first element is printed:
for <AB C D B E F>
If you only want to test against a start condition and have no stop condition, *
can be used as such.
for <A B C D E>
For the sed
-like version, which does not try $_
on the stop condition after succeeding on the start condition, see fff.
This operator cannot be overloaded, as it's handled specially by the compiler.