Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
When I try this, I get empty lines instead of the contents of the hashes. Obviously I don't have the syntax quite right to do what I want. Any suggestions?#!/usr/bin/perl -w # Make an array of hashes very explicitly. # This part works. @months = (); %m = ( full => "january", abbrev => "jan", number => 1, ); push @months, \%m; %m = ( full => "february", abbrev => "feb", number => 2, ); push @months, \%m; %m = ( full => "march", abbrev => "mar", number => 3, ); push @months, \%m; # etc # Now try to print it back out again. # This part doesn't work. while (<@months>) { print "$_->{full}\n"; print "$_->{abbrev}\n"; print "$_->{number}\n\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looping through an Array of Hashes
by trs80 (Priest) on Feb 21, 2002 at 23:39 UTC | |
by screamingeagle (Curate) on Feb 23, 2002 at 07:07 UTC | |
|
Re: Looping through an Array of Hashes
by giulienk (Curate) on Feb 21, 2002 at 22:52 UTC | |
|
Re: Looping through an Array of Hashes
by Anonymous Monk on Apr 19, 2002 at 07:00 UTC | |
by xorl (Deacon) on Jun 15, 2006 at 16:13 UTC |