in reply to Re: Generate Array of Hashes WITHOUT References
in thread Generate Array of Hashes WITHOUT References

That is only half a third of it LanX :)
#!/usr/bin/perl -- # reading from file # format: LEAD=fred FRIEND=barney # # # #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; my @AoH; while ( <> ) { my %rec; for my $field ( split ) { my( $key, $value ) = split /=/, $field; $rec{$key} = $value; ## second half } push @AoH, \%rec; } dd( \@AoH ); __END__

Replies are listed 'Best First'.
Re^3: Generate Array of Hashes WITHOUT References
by LanX (Saint) on Sep 09, 2014 at 09:20 UTC
    Hameed already posted this.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      Hi LanX,

      > Hameed already posted this.

      Sort of, but he redesigned the code so much that it no longer created more than element in the array. See how there is only 1 loop. Part of the problem with this is, it doesn't demonstrate how %rec should be reinitialised at the start of each iteration of the outer loop (though I now know this).

Re^3: Generate Array of Hashes WITHOUT References
by tel2 (Pilgrim) on Sep 10, 2014 at 23:03 UTC
    Good answer, Anonymous Monk.
    Thank you!