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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.