rampant selectrow_array misuse
Benton, Kevin
kevin.benton at amd.com
Fri Aug 26 14:33:34 UTC 2005
> > Both of these functions, as their names imply, return arrays.
>
> That's not actually true, as far as I can tell. DBI docs are strangely
> hard to find on the net, but I tend to use
> http://www.he.net/info/mysql/dbi.html
> or a more up-to-date copy thereof. (I'm linking to that one because
I've
> just found my bookmark to perldoc.com is broken.)
>
> "This utility method combines prepare, execute and fetchrow_array into
a
> single call. If called in a list context it returns the first row of
> data from the statement. If called in a scalar context it returns the
> first field of the first row."
Correct me if I'm wrong, but I think Dave's main point is still valid -
if the function returns a null value, the while loop ends, correct?
In any case, I believe Dave has another valid point - even if it is
technically correct to use the scalar context, style-wise, it seems to
me it would be more clear (better self-documenting) if we use array
context instead by wrapping the variable with ()'s. This seems
especially true to me if you "select foo, bar from baz"; In either
case, to prevent inconsistent results, I think we should use one or the
other, not both.
On using arrayrefs, I think that as long as the selectrow_array and the
variable assignment are very close together, the additional overhead
required to deal with hashes isn't worth it.
---
Kevin Benton
Perl/Bugzilla Developer
Advanced Micro Devices
The opinions stated in this communication do not necessarily reflect the
view of Advanced Micro Devices and have not been reviewed by management.
This communication may contain sensitive and/or confidential and/or
proprietary information. Distribution of such information is strictly
prohibited without prior consent of Advanced Micro Devices. This
communication is for the intended recipient(s) only. If you have
received this communication in error, please notify the sender, then
destroy any remaining copies of this communication.
More information about the developers
mailing list