Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

String comparison

by Anonymous Monk
on Feb 01, 2000 at 07:49 UTC ( #2640=perlquestion: print w/replies, xml ) Need Help??

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

if ("STRING" == "STRING"){ print "true"; } Always returns true. How do you compare two strings?

Replies are listed 'Best First'.
RE: String comparison
by vroom (His Eminence) on Feb 01, 2000 at 07:55 UTC
    Well "STRING" is equivalent to "STRING". To test string equality you need to use eq ie.
    if($string1 eq $string2){print "Yippee!"}
    == only works for numbers

    Tim Vroom | vroom | vroom@cs.hope.edu
RE: String comparison
by Anonymous Monk on Feb 02, 2000 at 08:18 UTC
    try: if (STRING eq STRING)
RE: String comparison
by Anonymous Monk on Feb 02, 2000 at 09:04 UTC
    Use Eq instead of ==
      or eq
RE: String comparison
by Anonymous Monk on Feb 01, 2000 at 12:07 UTC
    use cmp to test equality for strings
      Uh, you should really use eq for string tests. cmp should be used for sorting string (actually determining order).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2023-05-29 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?