in reply to Easy way to find data in hash or get subset of hash
To avoid the loop, put the conditions given by roboticus, above, into the block of a grep:
#! perl use strict; use warnings; use Data::Dump; my %LPAR_config = ( lpar1 => { profile1 => {}, profile2 => {}, frame => 'frame1', lpar_id => '1', }, lpar2 => { profile1 => {}, profile2 => {}, frame => 'frame1', lpar_id => '2', }, lpar3 => { profile1 => {}, profile2 => {}, frame => 'frame2', lpar_id => '1' }, lpar4 => { profile1 => {}, profile2 => {}, frame => 'frame2', lpar_id => '2', }, ); my @matches = grep { $LPAR_config{$_}->{frame } eq 'frame2' && $LPAR_config{$_}->{lpar_id} eq '1' } keys %LPAR_c +onfig; dd @matches;
Output:
1:43 >perl 560_SoPW.pl "lpar3" 1:44 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Easy way to find data in hash or get subset of hash
by T_I (Novice) on Mar 05, 2013 at 16:02 UTC |