KishKishore has asked for the wisdom of the Perl Monks concerning the following question:
Hi, In the below code, If the 'line' matches with any of 'var1' or 'var2', then only it should go into if block.
But, even though none of the variables are matching with line, the code is executing lines inside if statement.
Can you please explain what is happening here ?
$line = 'xyz'; $var1 = ''; $var2 = 'abc'; $check = 'Yes'; if((($line =~ m/$var1/i) || ($line =~ m/$var2/i)) and ($check =~ m/YES +/i)) { print "Inside if\n";} else {print "Outside if\n";}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Issue with matching regex
by Athanasius (Archbishop) on Oct 20, 2022 at 06:06 UTC | |
by choroba (Cardinal) on Oct 20, 2022 at 08:15 UTC | |
by hippo (Archbishop) on Oct 20, 2022 at 08:32 UTC | |
by rsFalse (Chaplain) on Oct 20, 2022 at 11:54 UTC | |
by Athanasius (Archbishop) on Oct 20, 2022 at 14:12 UTC | |
Re: Issue with matching regex
by jwkrahn (Abbot) on Oct 20, 2022 at 06:12 UTC |