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

Re: pushing an anonymous hash onto an array on the fly

by SuicideJunkie (Priest)
on Feb 22, 2013 at 22:53 UTC ( #1020244=note: print w/ replies, xml ) Need Help??


in reply to pushing an anonymous hash onto an array on the fly

I don't see the point of making it one line, but sure you can do it:

use strict; use warnings; use List::MoreUtils qw(mesh); use Data::Dumper; my @array = ('source|ex|stat|ex2|desc|dep|ind'); my @columns = qw<source_id exchange_id status exchange desc depth_flag + depth_indic>; my @AoH; foreach (@array) { push @AoH, { mesh(@columns, @{[split /\|/,(shift @array)]}) } ; }; print Dumper @AoH;
Gives:
C:\>perl test.pl $VAR1 = { 'source_id' => 'source', 'desc' => 'desc', 'status' => 'stat', 'depth_indic' => 'ind', 'depth_flag' => 'dep', 'exchange_id' => 'ex', 'exchange' => 'ex2' }; C:\>


Comment on Re: pushing an anonymous hash onto an array on the fly
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2015-07-06 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (80 votes), past polls