Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Map list of hashrefs

by AnomalousMonk (Canon)
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 perusing the Monastery: (5)
As of 2015-11-27 05:17 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (718 votes), past polls