RedJeep has asked for the wisdom of the Perl Monks concerning the following question:
Ok, this should be very basic. For the life of me I can't figure it out. I searched and searched. Maybe you can help?
In one of my programs I found this wrong way
if ($sender_transaction_type !~ /3|21/)
The above code is wrong, is bad, works sometimes. I know this is wrong. Trying to figure out the right way. I wrote the little test script below.
In the below script the multi-compare Option Equals works fine. But the multi-compare Option Not Equal does not work. Why? How to fix?
For example, set $a = 77 and the Option Not Equal does not work.
Thanks for the help!
use strict; $a = 8; #Try using 7 and see how second loop does not evaluate correct +ly ## Examples # $a = 44 evaluates ok for both options # $a = 33 evaluates ok for both options # $a = 3 does not evalute correctly on Option Not Equal # $a = 77 does not evalute correctly on Option Not Equal # $a = 8 does not evalute correctly on Option Not Equal ## Option Equal if (($a == 3) || ($a == 77) || ($a == 8)) { print "$a must be a 3 77 or 8\n"; } else { print "$a is not a 3 77 or 8\n"; } print "\n"; ## Option Not Equal if (($a != 3) || ($a != 77) || ($a != 8)) { print "$a is not a 3 77 or 8\n"; } else { print "$a is a 3 77 or 8\n"; }
Back to
Seekers of Perl Wisdom