Perl Tutorials -Part 31 – The equality operator

Posted on May 27, 2010. Filed under: Perl Tutorials |


#example of perl misleading if-then statement
$a = 5;
print “The value of the variable is $a. \n”;
# statement $a = 3 returns true.
if($a = 3)      #wrong!
{
        print “exactly three \n”;
        print “The value of the variable is $a. \n”;
}

Output:

1
2
3
The value of the variable is 5. 
exactly three 
The value of the variable is 3.
Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: