($a = 20) is an assignment so the if statement is testing the success of the
assignment, not a comparison - not what you want here.
 
Change it to ($a == 20), this will test numerically whether $a contains 20.
eq can be used for string comparisons
 
 
Jim

-----Original Message-----
From: Michael J Alexander [mailto:[EMAIL PROTECTED]]
Sent: 26 November 2002 16:19
To: Perl List
Subject: If - Else What?


Mike Here

        Can someone tell me why this simple bit of code doesn't work? The
"If" statement prints even when it's false. 


$x = 20;
$y = 15.5;
$z = .05;
$a = $x+$y;

print "a equals $a.\n";

if ($a = 20) {print "a is equal to 20.\n";}

else {print "a is not equal to 20.\n";}


Reply via email to