Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Apr 252010
 

eq vs == in Perl

Answer:

1. eq

It perform string comparison.

my $foo = "123";
my $bar = "123";

print $foo eq $bar; # output "1"

2. ==

It perform numeric comparison, string is first converted to numeric value before compare.

my $foo = "foo";
my $bar = "bar";

print $foo == $bar; # output "1", since 0 = 0 as strings are converted to 0 in both variables

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>