in reply to how to get a value corresponding to a key

What you have tried so far? You should go through perldata. Here is a small example.

%hash =("name" =>"john", "age"=>"25", "job"=>"programer", "location"=> +"US"); while (($key, $val) = each %hash) { if ($matchkey =~ /^$key$/) #if matches the particular key { $var = $hash{$key}; } }

or even simply,

$matchkey eq $_ ? $var = $hash{$_} : $var='' for keys %hash;

still simply as davorg suggested

$var = $hash{$matchkey}

updated

Prasad

Replies are listed 'Best First'.
Re^2: how to get a value corresponding to a key
by davorg (Chancellor) on Jul 20, 2005 at 12:10 UTC

    That seems rather a long way to go about it. What does your method give you that simply using $var = $hash{$matchkey} doesn't?

    Also why use $matchkey =~ /^$key$/ when $matchkey eq $key achieves the same thing without the overhead of invoking the regex engine? Regular expressions are a powerful tool, but they are often unnecessarily complex for the task in hand.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg