micmac has asked for the wisdom of the Perl Monks concerning the following question:
into this:my $element = { 'check' => { 'field' => 'OLK_BO_BK_TYPE' }, 'type' => 'case', 'case' => [ { 'value' => '1', 'resultset' => 'BROKER' }, { 'value' => '3', 'resultset' => { 'field' => 'OLK_BO_BK_DESC' }, }, ] };
my $element = { 'check' = 'OLK_BO_BK_TYPE', 'type' => 'case', 'case' => [ { 'value' => '1', 'resultset' => 'BROKER' }, { 'value' => '3', 'resultset' => 'OLK_BO_BK_DESC' }, ] };
hash_walk($element); sub hash_walk { my $element = shift; if(ref($element) =~ /HASH/ ) { foreach my $key (keys %$element) { if ($key =~ /field/) { # do something here? print "found $$element{$key}\n"; } hash_walk($$element{$key}); } } elsif (ref($element) =~ /ARRAY/) { foreach my $index (@$element) { hash_walk($index); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: replace a key with its value
by moritz (Cardinal) on Jul 08, 2009 at 15:22 UTC | |
|
Re: replace a key with its value
by spazm (Monk) on Jul 08, 2009 at 19:26 UTC | |
by spazm (Monk) on Jul 08, 2009 at 19:35 UTC | |
by micmac (Acolyte) on Jul 08, 2009 at 19:56 UTC |