http://www.perlmonks.org?node_id=87089

JackDno7 has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a script that takes as the input the name of a city, and then matches it to a field in a data file to get the proper output. Two of the cities I deal with are Evansville and South Bend. When I compare them using the eq comparator, they don't match (as they shouldn't). But when I use the == comparator, the output says they are equal. Why is that?

Replies are listed 'Best First'.
Re: Why are these 2 strings equal?
by bikeNomad (Priest) on Jun 09, 2001 at 02:17 UTC
    Because when you use == the strings are converted to numbers. And both these strings equal 0 when converted to numbers. And 0 == 0.
Re: Why are these 2 strings equal?
by japhy (Canon) on Jun 09, 2001 at 01:44 UTC
    Because == is for numbers. Use eq. Read some documentation (perlop).
Re: Why are these 2 strings equal?
by marcink (Monk) on Jun 10, 2001 at 00:47 UTC
    Because you don't use '-w' that would warn you about type mismatch. Use it (together with 'use strict;' and save yourself a lot of hassle.

    -mk