Bill Conlon wrote:
> Thanks, the hash reference gets pushed onto the list, and now exposes
> more of my ignorance.
>
> Say I have three rows returned by my SQL query. The while loop
> properly generates three hashes, and @servers grows to contain three
> elements, but each has the same hash reference, which ends up pointing
> to the last created hash. How do I programatically generate a series
> of hash references?
You have to localize the scope of the new hash that you are creating
using 'my'. If you don't then a new hash isn't created for each iteration.
while (@ary = $sth->fetchrow_array ())
{
my %hash = (
base_url => $ary[1],
max_depth => $ary[2],
);
push @servers, \%hash;
}
HTH
>
> tia.
>
> On Monday, November 22, 2004, at 06:34 PM, Bill Moseley wrote:
>
>
>>On Mon, Nov 22, 2004 at 04:41:11PM -0800, Bill Conlon wrote:
>>
>>>I'm trying it along these lines:
>>>
>>>while (@ary = $sth->fetchrow_array ())
>>>{
>>>%hash = (
>>> base_url => $ary[1],
>>> max_depth => $ary[2],
>>> );
>>> push @servers, %hash;
>>
>> push @servers, \%hash;
>>
>>You want to push a hash reference on the list.
>>
>>
>>
>>--
>>Bill Moseley
>>moseley@hank.org
>>
>>Unsubscribe from or help with the swish-e list:
>> http://swish-e.org/Discussion/
>>
>>Help with Swish-e:
>> http://swish-e.org/current/docs
>> swish-e@sunsite.berkeley.edu
>>
>
>
--
Michael Peters
Developer
Plus Three, LP
Received on Wed Nov 24 12:11:19 2004