Here is my environment: Win32 + AS perl v5.8.7 build 813
Example code:
my $flip = 'vh'; if( $flip =~/v|y/i ){ print "i only -> flip v|y\n"; } if( $flip =~/h|x/i ){ print "i only -> flip h|x\n"; } if( $flip =~/v|y/ig ){ print "ig -> flip v|y\n"; } if( $flip =~/h|x/ig ){ print "ig -> flip h|x\n"; } if( $flip =~/v|y/g ){ print "g only -> flip v|y\n"; } if( $flip =~/h|x/g ){ print "g only -> flip h|x\n"; } #change $flip print "----------------------\n\$flip is now $flip\n------------------ +----\n"; $flip = 'hv'; if( $flip =~/v|y/i ){ print "i only -> flip v|y\n"; } if( $flip =~/h|x/i ){ print "i only -> flip h|x\n"; } if( $flip =~/v|y/ig ){ print "ig -> flip v|y\n"; } if( $flip =~/h|x/ig ){ print "ig -> flip h|x\n"; } if( $flip =~/v|y/g ){ print "g only -> flip v|y\n"; } if( $flip =~/h|x/g ){ print "g only -> flip h|x\n"; }
Output with comments:
i only -> flip v|y (expected this) i only -> flip h|x (expected this) ig -> flip v|y (expected this) ig -> flip h|x (expected this) g only -> flip h|x (expected this) <--- didn't match v ---------------------- $flip is now vh ---------------------- i only -> flip v|y (expected this) i only -> flip h|x (expected this) ig -> flip v|y (expected this) <--- didn't match h g only -> flip v|y (expected this) <---- didn't match h

I was expecting all of these cases to work. But I get odd behavior when I use the 'g' switch in my regex when I switch the string around. Is this a bug? or can someone fill an obvious gap in my understanding of using the g switch in a regex? I didn't know that separate if statements could do this.
Thanks,
JamesNC

In reply to Odd regex results with g switch by JamesNC

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.