Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Map list of hashrefs

by AnomalousMonk (Abbot)
on Nov 22, 2011 at 19:12 UTC ( #939517=note: print w/ replies, xml ) Need Help??

in reply to Map list of hashrefs

Assuming you already have a bunch of hashrefs you need to corral, I would consider something like this:

>perl -wMstrict -le "my @vals = qw(val1 val2 val3); my ($hr1, $hr2, $hr3) = ({a => 1}, {b => 2}, {c => 3}); my @h_refs = ($hr1, $hr2, $hr3); ;; die 'arrays not same size' if @h_refs != @vals; ;; $h_refs[$_]->{k} = $vals[$_] for 0 .. $#vals; ;; use Data::Dumper; print Dumper $hr1, $hr2, $hr3; " $VAR1 = { 'k' => 'val1', 'a' => 1 }; $VAR2 = { 'k' => 'val2', 'b' => 2 }; $VAR3 = { 'c' => 3, 'k' => 'val3' };

Comment on Re: Map list of hashrefs
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2015-08-31 20:37 GMT
Find Nodes?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...

    Results (364 votes), past polls