in reply to Looping through an Array of Hashes
This gets rid of the temp %m's you were creating as well and avoid the problem of the last reference wining, which is what you would have seen if you had changed the while to a foreach without changing the way you did your push.#!/usr/bin/perl -w # Make an array of hashes. # This part works. use strict; # <- Note the use strict my @months = (); my %m = (); push @months, { full => "january", abbrev => "jan", number => 1, }; push @months, { full => "february", abbrev => "feb", number => 2, }; push @months, { full => "march", abbrev => "mar", number => 3, }; # etc # Now try to print it out. foreach my $month (@months) { print "$month->{full}\n"; print "$month->{abbrev}\n"; print "$month->{number}\n\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Looping through an Array of Hashes
by screamingeagle (Curate) on Feb 23, 2002 at 07:07 UTC |