http://www.perlmonks.org?node_id=961684


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 }

Replies are listed 'Best First'.
Re^2: How to create an array of hashes return form a subroutine
by gepebril69 (Scribe) 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.