http://qs1969.pair.com?node_id=2640

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).