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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|