in reply to Multiple if statements matching part of one variable problem
Effectively, you are thus copying the contents of $gw into the variables $a, $b ... and are not directly checking for the match of $gw anymore. This approach will then return what you had initially expected:$gw="abcdefgh"; if ( ( my $a = $gw ) =~ m/abc/ig){ print pos( $a ), ": abc\n"; } if ( ( my $b = $gw ) =~ m/cde/ig){ print pos( $b ), ": cde\n"; } if ( ( my $c = $gw ) =~ m/defgh/ig){ print pos( $c ), ": defgh\n"; } if ( ( my $d = $gw ) =~ m/gh/ig){ print pos( $d ), ": gh\n"; } if ( ( my $e = $gw ) =~ m/fg/ig){ print pos( $e ), ": fg\n"; }
Hope this helps.3: abc 5: cde 8: defgh 8: gh 7: fg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multiple if statements matching part of one variable problem
by jmclark (Novice) on Sep 10, 2008 at 14:14 UTC | |
by ikegami (Patriarch) on Sep 10, 2008 at 14:20 UTC | |
by GrandFather (Saint) on Sep 10, 2008 at 14:35 UTC |