case OP_DEFINED: case OP_EXISTS:
case OP_MATCH: case OP_EOF:
+ case OP_FLOP:
+
return TRUE;
case OP_CONST:
return TRUE;
else
return FALSE;
-
- case OP_FLOP:
- /* Detect "..." flip-flop operator */
- if (cUNOPo->op_first->op_flags & OPf_SPECIAL)
- return TRUE;
/* FALL THROUGH */
default:
=item *
-the C<...> flip-flop operator (but B<not> the two-dot version C<..>, which
-is used to construct and test against numerical or string ranges).
+the C<..> and C<...> flip-flop operators.
=back
Array Regex array grep grep /$b/, @$a
Any Regex pattern match $a =~ /$b/
- undef Range[4] always false
- Any Range[4] in range
-
Any Num numeric equality $a == $b
- Num numish[5] numeric equality $a == $b
+ Num numish[4] numeric equality $a == $b
Any Any string equality $a eq $b
2 - that is, each element smart-matches the element of same index in the
other array. [3]
3 - If a circular reference is found, we fall back to referential equality.
- 4 - a range is written EXPR..EXPR (using the C<..> range operator, but
- NOT the three-dot version C<...>, which will be treated as a boolean
- operator). Numeric ranges will use numeric comparison: that is,
- "4.5 ~~ 3..5" will be true.
- 5 - either a real number, or a string that looks like a number
+ 4 - either a real number, or a string that looks like a number
The "matching code" doesn't represent the I<real> matching code,
of course: it's just there to explain the intended meaning. Unlike
use strict;
use warnings;
-use Test::More tests => 118;
+use Test::More tests => 122;
# The behaviour of the feature pragma should be tested by lib/switch.t
# using the tests in t/lib/switch/*. This file tests the behaviour of
my $n = 0;
for my $l qw(a b c d) {
given ($l) {
+ when ($_ eq "b" .. $_ eq "c") { $n = 1 }
+ default { $n = 0 }
+ }
+ ok(($n xor $l =~ /[ad]/), 'when(E1..E2) evaluates in boolean context');
+ }
+}
+
+{
+ my $n = 0;
+ for my $l qw(a b c d) {
+ given ($l) {
when ($_ eq "b" ... $_ eq "c") { $n = 1 }
default { $n = 0 }
}