Re: looping over an array of hashes

2006-04-28 Thread Mr. Shawn H. Corey
On Fri, 2006-28-04 at 15:40 +0100, Graeme McLaren wrote: > Hi all, I need to loop over an array of hashes and assign a new hashref if a > condition is met: > > I have a scalar which contains an array of hashes: > > $locations = [ > { > 'location_name' => 'Fionas House', >

looping over an array of hashes

2006-04-28 Thread Graeme McLaren
Hi all, I need to loop over an array of hashes and assign a new hashref if a condition is met: I have a scalar which contains an array of hashes: $locations = [ { 'location_name' => 'Fionas House', 'location_id' => '0027' }, {

Re: Looping over an array of hashes problem

2005-09-08 Thread John W. Krahn
Graeme McLaren wrote: > Morning all, I have a problem that I can't see a way around. Basically > I have an array of hashes and I want to get the key and value of each > hash but with the following code I'm getting: > > Type of arg 1 to keys must be hash (not array element) at > /usr/lib/perl5/ven

Re: Looping over an array of hashes problem

2005-09-08 Thread Jeff Pan
maybe u would try: foreach my $key (keys %{$AoH[$map_loop{$i}]}) { ... } because $AoH[$map_loop{$i}] is just a ref,so u get wrong. On Thu, 08 Sep 2005 09:42:33 +0100, "Graeme McLaren" <[EMAIL PROTECTED]> said: > Morning all, I have a problem that I can't see a way around. Basically I > ha

Looping over an array of hashes problem

2005-09-08 Thread Graeme McLaren
Morning all, I have a problem that I can't see a way around. Basically I have an array of hashes and I want to get the key and value of each hash but with the following code I'm getting: Type of arg 1 to keys must be hash (not array element) at /usr/lib/perl5/vendor_perl/Purchaser/Common.pm l

Re: looping over an array of hashes

2001-06-01 Thread Walt Mankowski
On Fri, Jun 01, 2001 at 03:29:43PM -0700, Chuck Ivy wrote: > First post, quick question: > > I've got an array of hashes that I'm defining the most basic way I can... > > my $gSeasonID; > my @season_list = ''; > while (@fields = $sth->fetchrow_array) { > $gSeasonID = $fields[0]; > $s

Re: looping over an array of hashes

2001-06-01 Thread Bill Stilwell
On Fri, Jun 01, 2001 at 03:29:43PM -0700, Chuck Ivy wrote: > First post, quick question: > > I've got an array of hashes that I'm defining the most basic way I can... > > my $gSeasonID; > my @season_list = ''; > while (@fields = $sth->fetchrow_array) { > $gSeasonID = $fields[0]; > $s

Re: looping over an array of hashes

2001-06-01 Thread Chas Owens
First ugly thought goes like this: my @season_list = ''; while (my @fields = $sth->fetchrow_array) { for (my $i = 1; $i < @fields; $i++) { $season_list[$fields[0]]{('number', 'title', 'active')[$i]} = $fields[$i]; } Second thought is: Why not use $sth->fetchrow_hashref? The only r

looping over an array of hashes

2001-06-01 Thread Chuck Ivy
First post, quick question: I've got an array of hashes that I'm defining the most basic way I can... my $gSeasonID; my @season_list = ''; while (@fields = $sth->fetchrow_array) { $gSeasonID = $fields[0]; $season_list[$gSeasonID]{number} = $fields[1]; $season_list[$gSeaso