Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Syntactic Confectionery Delight
 
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 examining the Monastery: (6)
As of 2014-04-21 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls