Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Extracting values from nested hashrefs

by Athanasius (Chancellor)
on Sep 12, 2012 at 12:46 UTC ( #993220=note: print w/replies, xml ) Need Help??


in reply to Re^2: Extracting values from nested hashrefs
in thread Extracting values from nested hashrefs

Here is an approach that should work no matter how complicated your data structure becomes (provided the data you want remains in the form humps => d):

#! perl use strict; use warnings; use Data::Dumper; my $animals = { gnu => { humps => 0, mascot_for => 'emacs', }, dromedary => { humps => 1, mascot_for => 'perl', }, camel => { humps => 2, mascot_for => 'perl', }, }; my $flat = Dumper($animals); print "$1\n" while $flat =~ / 'humps' \s+ => \s+ (\d+) /gx;

Output:

2 0 1

TMTOWTDI.

Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993220]
help
Chatterbox?
[choroba]: Oh, the Czech one playing the German composition?
[choroba]: BTW, the elections are over. We already have the final results.
[choroba]: I should probably apply for a job somewhere abroad.
[LanX]: nope this one One day the triangle player of an orchestra gets very ill and goes to the hospital.. ..

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-10-21 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (270 votes). Check out past polls.

    Notices?