Re: unfamiliar array reference
- From: merlyn@xxxxxxxxxxxxxx (Randal L. Schwartz)
- Date: Sat, 18 Aug 2007 19:03:58 -0700
"Paul" == Paul Lalli <mritty@xxxxxxxxx> writes:
while ($array_ref = $sth1->fetchrow_arrayref) {
push @stash, [ @$array_ref ]; ##copy array contents
Paul> Is that seriously from the book? UGH. Just declare $array_ref in the
Paul> proper scope, and there's no need to take a reference to a dereference
Paul> of the reference.
Yes there is.
Paul> while (my $array_ref = $sth1->fetchrow_arrayref) {
Paul> push @stash, $array_ref;
Paul> }
Your code breaks on older versions of DBI, for which the book was written.
In older versions of DBI, the value of $array_ref would have been
the same for each row returned. There was this clause in "perldoc DBI":
Note that the same array reference is returned for each fetch, so don't
store the reference and then use it after a later fetch. Also, the elements
of the array are also reused for each row, so take care if you want to take
a reference to an element.
Yes, DBI has matured since the book, but I wouldn't jump to conclusions about
the validity of the code in the book. After all, Tim Bunce co-wrote the book,
and there's nobody on the planet who knows more about DBI.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxxxxxx> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
.
- Follow-Ups:
- Re: unfamiliar array reference
- From: Paul Lalli
- Re: unfamiliar array reference
- References:
- unfamiliar array reference
- From: petelink1
- unfamiliar array reference
- Prev by Date: Re: Using text files as database to interact with DBI
- Next by Date: Mac::Carbon and Mac::Sound Documentation?
- Previous by thread: Re: unfamiliar array reference
- Next by thread: Re: unfamiliar array reference
- Index(es):
Relevant Pages
|
Loading