in reply to Re: Search List
in thread Search List

Aside from note by Roy Johnson, I would change
if ( $searchlist{$_} ) {print "Match Found"}
to
if ( exists $searchlist{$_} ) {print "Match Found"}
since your test would add a entry to the hash on each word which isn't there.
Update: This is wrong, see reply.

Replies are listed 'Best First'.
Re^3: Search List
by holli (Abbot) on Dec 25, 2005 at 00:34 UTC
    That's wrong. Just looking up a hash key does not autovivfy that key. Consider
    my %h = (); print "found" if $h{somekey}; print %h;
    which prints nothing. The key "somekey" is not autovivied.


    holli, /regexed monk/
      Oh my, You're right! I've always thought that exists() is a ugly exception to the rule, that $hash{key} autovivify ``key'' if it doesn't exist. However, using exists() is more explicit and I think I'll still use it in turbo-clean code. Thanks for enlightenment.