Tuesday, 6 August 2013

Perl simple comparison == vs eq

Perl simple comparison == vs eq

On the accepted answer for perl string compare with "eq" vs "=="
it says that First, eq is for comparing strings; == is for comparing numbers.
"== does a numeric comparison: it converts both arguments to a number and
then compares them." "eq does a string comparison: the two arguments must
match lexically (case-sensitive)"
You can ONLY use eq for comparing strings but
both eq AND == works for comparing numbers
numbers are subset of strings so i just dont understand why you would ever
use ==
Is there a reason why you would want to use == for comparing numeric
values over just using eq for all?

No comments:

Post a Comment