in reply to Re: Testing for key/value match
in thread Testing for key/value match

If you want to test whether a certain key exists and has the value you expect, you can do this

if (defined $foo{'bar'} and $foo{'bar'} eq 'baz'){ }
perhaps you mean exists?

if (exists $foo{'bar'} and $foo{'bar'} eq 'baz'){ }
reminder to all: in an array or hash lookup, defined tests for definedness of the value of the array index or hash key, which may not be what you mean. use exists to test whether the array index or hash key is present.

~Particle *accelerates*

Replies are listed 'Best First'.
Re: Re: Re: Testing for key/value match
by perlplexer (Hermit) on May 10, 2002 at 15:10 UTC
    No, defined() is what I wanted to say.
    The value may exist but may be undefined, in which case the 'eq' will produce a warning.

    --perlplexer
      so if undefined is what you expect, it looks like none of these solutions will work.

      ~Particle *accelerates*