in reply to Matching a KEY in a HASH

That's what Perl does best!
$value = $category{"Anim"};
No "searching" required.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Matching a KEY in a HASH
by SysAdm (Novice) on May 14, 2001 at 20:22 UTC
    I must not be making myself clear...

    The $variable = "" could = Anim or CAD or anything in the list...

    My question is ... How do I search the HASH to match the $variable, but print the VALUE only...

    make sense?
      I must not be making myself clear.

      The point of a hash is that a hash itself can find a value for a given key trivially.

      $value_you_are_looking_for = $category{$variable};
      There's no searching required. If there's an element with a key of $variable, then $value_you_are_looking_for has it. Otherwise, it gets undef.

      -- Randal L. Schwartz, Perl hacker