print map { $_->{State} if $_->{ID} == 32 } @{ $hash->{data} };
ccfc1986: Be aware that the processing of this data flow is IMHO problematic. For every element processed that does not match the desired ID an extraneous empty string is returned (the '' pairs in the example below), the result of the false evaluation of the if conditional expression. I think NetWallah's use of grep is preferable.
c:\@Work\Perl\monks>perl -wMstrict -le "my $hash = { 'data' => [ { 'ID' => 32, 'State' => 'Stopped' }, { 'ID' => 33, 'State' => 'Stopped' }, { 'ID' => 31, 'State' => 'Running' }, ], }; ;; my @ra = map { $_->{State} if $_->{ID} == 32 } @{ $hash->{data} }; printf qq{'$_' } for @ra; " 'Stopped' '' ''
In reply to Re^2: MIS-PARENTED: PLEASE REAP: accessing data in hash
by AnomalousMonk
in thread accessing data in hash
by ccfc1986
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |