shan_emails has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

How can i assign using hash array the key as variable name and value as value

My coding is

while ( ($key, $value) = each(%KPI) ) { $key=$value; print "key =$key : value =$value \n"; }


Thanks in Advance,
Shanmugam A.

Replies are listed 'Best First'.
Re: hash array the key as variable name and value as value
by linuxer (Curate) on Dec 01, 2008 at 10:02 UTC
Re: hash array the key as variable name and value as value
by moritz (Cardinal) on Dec 01, 2008 at 09:47 UTC
    While brsaravan's answer is correct (and requires no strict 'refs"; under strict), the usual answer is "don't".

    Symbolic references are fraught with peril, and usually it's much better to use the hash all the time instead.

Re: hash array the key as variable name and value as value
by brsaravan (Scribe) on Dec 01, 2008 at 09:42 UTC
    If my understanding is correct (You want to use the hash key as variable name) then you can use
    $$key = $value
      Wow... its working fine.
      Thank you very much