in reply to Existing in hash

The "=" sign in your if makes me wonder ;)
Why don't you want to use something as simple as? :

if ($hash{$var1} == $var2) { print "You are in\n"; } else { print "Bad, monkay, bad!\n"; }

If you insist on more checks, you can do

if (defined($var1)) { ... }

thingy. Or you can even do

if (defined($hash{$var1}) && length($hash{$var1}) > 0) { ... }

staff. It's all up to you... :)

Leonid Mamtchenkov

Replies are listed 'Best First'.
Re: Re: Existing in hash
by bart (Canon) on Apr 28, 2003 at 09:50 UTC
    I think you want eq instead of ==. This is not PHP, or Javascript, or whatever... :) In perl, == does numerical comparisons only.

      The == operator is best for comparing numbers, or for comparing for identical references (references to the same data object). The example here didn't give much to go on.

      If $var1 and $var2 are references, the $var1 eq $var2 would also work: it discovers that "HASH(0x804c88c)" eq "HASH(0x804c88c)", but takes the extra time to stringize both sides.

      --
      [ e d @ h a l l e y . c c ]

        The guy was talking about comparing $name and $pass, so my guess is that the latter (which I presume to be the hash value) is a string. Comparing "foo"=="bar" will return true, which isn't worth much as a password check.