Maybe "not the same thing" but definitely not "'keep checking for more matches'" (within the current when, anyway).
At least, not in the same sense as the /g modifier in a regex. Observe:
#!/usr/bin/perl use strict; use warnings; use 5.012; # 901284 my $count=0; my $foo = "X x y y x y Z"; say "First, with a simple substitution '/g'"; my $simplecount = $foo =~ s/x/o/g; say " \$foo: $foo; \n \$simplecount: $simplecount (i.e., 'x's changed) +"; $foo =~ s/o/x/g; say "\$foo restored: $foo \n"; say 'Now, with given/when and =~ /x/g'; given( $foo ) { when ( $foo =~ /x/g ) { say "\$foo contains an x"; $count++; say "\$foo: $foo; \n \$count: $count;"; continue } when ( /y/ ) { say "\n \$foo contains a y"; } default { say "$foo does not contain a y"; } } say "\n Final \$count of 'x' in given/when matching 'x': $count"; say "\n $foo";
OUTPUT:
First, with a simple substitution '/g' $foo: X o y y o y Z; $simplecount: 2 (i.e., 'x's changed) $foo restored: X x y y x y Z Now, with given/when and =~ /x/g $foo contains an x $foo: X x y y x y Z; $count: 1; $foo contains a y Final $count of 'x' in given/when matching 'x': 1 X x y y x y Z
One possible reading is that continue's precedence terminates the matching. Perhaps a wiser head will explain (and correct, as necessary).
Update: typo fixed (from /s/g to /x/g) at line 15 and in the output. Gnahh!
In reply to Re^3: given/when one case prefixes another
by ww
in thread given/when one case prefixes another
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |