Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Array to Array of hashes

by NetWallah (Canon)
on Oct 27, 2015 at 16:33 UTC ( [id://1146134]=note: print w/replies, xml ) Need Help??


in reply to Array to Array of hashes

There are at least 2 issues:
  • @data is an array, but is being assigned an array-REF. Use Parens(), instead of square brackets[] for the outermost delimiter
  • the "for" statement aliases $_ to each element. So in you case, you should be using $_ as the index, instead of your hard-coded "1" and "2"
  • A perl programmer would prefer "for (@data)" instead of "for (0..$#data)"

        The best defense against logic is ignorance.

Replies are listed 'Best First'.
Re^2: Array to Array of hashes
by Anonymous Monk on Oct 27, 2015 at 17:34 UTC
    The data was a Dump from the array @data, but how you were saying, how would you use "$_" instead of assigning or hard-code "1" and "2" ... to the code?
    my @data = ( ["John","10/30","Main Street"], ["Mary","6/1","Oak Street"] # more data here ); foreach (@data) { push @AoH, { NAME => $_, DOB => $_, ADDRESS => $_, } }
    Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-19 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found