Tachoknight has asked for the wisdom of the Perl Monks concerning the following question:
But it is wrong, the second expression is always false, even if the sentence does contain a "bar". I rewrote it to say:if ($sentence =~ /foo/gis && $sentence =~ /bar/gis) { # do something further with $sentence }
but that doesn't work either! The only way I could get it to work was:if ($sentence =~ /foo/gis) { if ($sentence =~ /bar/gis) { # now do something with the sentence } }
I apologize if this is a real "duh" question; it seemed like it would make sense to me (a C++ programmer) but the second try really confused me as I figured it surely couldn't fail, it was just doing another search. I beg wisdom and mercy for my cluelessness. Thank you, Tachoif ($sentence =~ /foo/gis) { my $final_test = $sentence; if ($final_test =~ /bar/gis) { # *now* do something with the sentence... } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using && with regex in an if() statement
by Roy Johnson (Monsignor) on Mar 14, 2006 at 17:02 UTC | |
by Tachoknight (Initiate) on Mar 14, 2006 at 22:20 UTC | |
|
Re: using && with regex in an if() statement
by kvale (Monsignor) on Mar 14, 2006 at 17:00 UTC | |
|
Re: using && with regex in an if() statement
by QM (Parson) on Mar 14, 2006 at 17:04 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |