Agnello George wrote:
Hi All
Hello,
I got a hash like this :
my %retrn = ( 0 => { 0 => ' successful<br>'},
1 => { 1 => 'insufficient<br>'},
2 => { 2 => 'txtfile missing<br>'},
3 => { 3 => 'bad dir<br>'},
);
( i know this hash looks funny , but is the hash i got to use )
suppose $stdout = 0;
i need to get the key
my key = keys %{ $retrn{ $stdout} } ;
That should probably be:
my $key = keys %{ $retrn{ $stdout} } ;
but i am not getting the desired out put which should be '0'
what am i doing wrong .
You are forcing scalar context with your assignment and keys() in scalar
context returns the number of keys in the hash, which in this case is 1
because you only have one key.
You need to force list context on the assignment which will return the
actual keys from the hash:
my ( $key ) = keys %{ $retrn{ $stdout} } ;
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/