Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Extracting values from nested hashrefs

by trizen (Friar)
on Sep 12, 2012 at 13:39 UTC ( #993227=note: print w/ replies, xml ) Need Help??


in reply to Extracting values from nested hashrefs

Using recursion:

use 5.010; my $animals = { gnu => { humps => 0, mascot_for => 'emacs', }, dromedary => { humps => 1, zzz => { humps => 'nested', aaa => { humps => 'really nested', xxx => 0, }, }, mascot_for => 'perl', }, }; sub print_humps { my $hash_ref = shift; foreach my $key (keys %{$hash_ref}) { if (ref $hash_ref->{$key} eq "HASH") { print_humps($hash_ref->{$key}); } elsif ($key eq 'humps') { say $hash_ref->{$key}; } } } print_humps($animals); __END__ 0 1 nested really nested


Comment on Re: Extracting values from nested hashrefs
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2014-07-10 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (207 votes), past polls