Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 taking refuge in the Monastery: (8)
As of 2014-12-20 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (99 votes), past polls