Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Map list of hashrefs

by AnomalousMonk (Monsignor)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (13)
As of 2014-09-02 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (25 votes), past polls