On Fri, Apr 29, 2011 at 2:33 PM, Rob Dixon <rob.di...@gmx.com> wrote:
> On 29/04/2011 09:47, Agnello George wrote:
>>
>>  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} } ;
>
> I assume this should read
>
>  my $key = keys %{ $retrn{ $stdout} } ;
>
> In list context the keys operator returns the list of all keys of a
> hash. But in a scalar context, as here, it returns the number of keys
> instead. I assume you are getting a value of 1 in $key when you are
> expecting 0?
>
> If there is always only a single key then you can write instead
>
>  my ($key) = keys %{ $retrn{ $stdout} } ;
>
> which will extract the first key of the list returned by keys. If you
> can't guarantee that then you should assign to an array instead:
>
>  my @keys = keys %{ $retrn{ $stdout} } ;
>

Ok , i see my fault , so i can also do something like this right

 if (stdout ==   (%$retrn{$stdout})  ) {
       ##so some code
    }



-- 
Regards
Agnello D'souza

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to