You should be using syntax like:
 
if ( $a == 20 ) { print ... }
 
When you say:
if ( $a = 20 ) { ... }
you are actually assigning the value 20 to $a.  Which was successful, hence
the if statement is evalutated to 'true'.
 
Regards,
 
Joshua Colson 
Systems Administrator 
Giant Industries, Inc. 
P (480) 585-8714 
F (480) 502-6641 

-----Original Message-----
From: Michael J Alexander [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 26, 2002 9:19 AM
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