develooper Front page | perl.beginners | Postings from February 2002

Re: Difference between == and eq

Thread Previous | Thread Next
From:
Leon
Date:
February 6, 2002 22:35
Subject:
Re: Difference between == and eq
Message ID:
008501c1b027$c34e8280$a74da9cb@S7575530
----- Original Message -----
From: "wim" <wdh@belbone.be>

> When I do:
>
> if ( $menuitem == "modify_router") {
>          print "Modify router<br>";
> } else {
>          print "Add router<br>";
> }
>
> it doesn't work. But when I change it to:
> How comes?

Apart from the fact that == is used for numeric comparison whilst eq is used
for string comparison, it would be of interest to note that == when used
with strings forces the strings to be read in numeric context which is zero.
Therefore the following returns true.

my $menuitem = 0; #change this to 1 and it will return false.

if ( $menuitem == 'modify_router') {
    print "Modify router<br>";
} else {
   print "Add router<br>";
}






_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About