Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to create an array of hashes return form a subroutine

by tangent (Curate)
on Mar 26, 2012 at 15:16 UTC ( #961684=note: print w/ replies, xml ) Need Help??


in reply to How to create an array of hashes return form a subroutine

You need to store a reference to each hash in the array, try this:

my @NameArray; my $endvalue = 5; for (my $i = 0; $i < $endvalue; $i++) { $NameArray[$i] = addnew($i); } for my $hash_ref (@NameArray) { print "$hash_ref->{firstname} $hash_ref->{famname}\n"; } sub addnew { my $index = shift; my %value; $value{firstname} = "John $index"; $value{famname} = "Johnson $index"; $value{street} = "Bellpark $index"; return \%value; # return a reference to the hash }


Comment on Re: How to create an array of hashes return form a subroutine
Download Code
Re^2: How to create an array of hashes return form a subroutine
by gepebril69 (Beadle) on Mar 26, 2012 at 16:20 UTC
    @Tangent, Thanks very much, so I was close, just missed an '\' @All others thanks for the help as well.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2015-07-06 05:06 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 (70 votes), past polls