This line is wrong:
if ($number4 == 1,2) {
I think you probably expected that $number4 will compare to 1 or to 2, and that if it is equal to either 1 or 2 you will have a Boolean "true" condition. But what really happens is that $number == 1 is evaluated, and then the result is thrown away. Then 2 is evaluated, and its value in a Boolean context turns out to be "true". So your conditional will always be true.
Consider this example:
print "Yes!\n" if ( 1 == 2, 3 );
The outcome will be "Yes!", because even though the conditional 1==2 is false, that evaluation is thrown away, and the "3" is evaluated numerically in Boolean context, and that will always be "true".
You probably want to say something like this:
if( grep { $number4 == $_ } 1, 2 ) {...
Or more simply...
if( $number4 == 1 || $number4 == 2 ) { ...
Or more legibly:
use List::Util 'any'; # ......... if( any { $number4 == $_ } 1, 2 ) {...
Dave
In reply to Re: Perl compare
by davido
in thread Perl compare
by waytoperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |