Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Why are these 2 strings equal?

by JackDno7 (Initiate)
on Jun 09, 2001 at 01:42 UTC ( [id://87089]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://87089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found