Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl Gotchas

         

sugarkane

10:38 am on Apr 5, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One programming error that always trips me up is using something like:

if ($foo=20) {&do_something;}

to test the value of a variable. ($foo=20) will always evaluate to 'true' and &do_something will always be called.

Sooo... who can see the problem here (and the solution), and who else suffers from repeated 'gotchas'?

littleman

7:14 am on Apr 6, 2001 (gmt 0)



if ($foo=20) {&do_something;}
should be
if ($foo==20) {&do_something;}
While the first example will give the value of 20 to $foo, the second example does the check if $foo equals 20.

'==' will return true if the what is on the left and right are numerically equal.