Here's a relevant snippet from the man page about "fetchrow_array":
If called in a scalar context for a statement handle that has more than one column, it is undefined whether the driver will return the value of the first column or the last. So don't do that. Also, in a scalar context, an "undef" is returned if there are no more rows or if an error occurred. That "undef" can't be distinguished from an "undef" returned because the first field value was NULL. For these reasons you should exercise some caution if you use "fetchrow_array" in a scalar context.
Now, it does seem like your query will return a single value per row, so maybe while ( my $market = $sth->fetchrow_array ) should work the way you expect. But maybe you shouldn't count on that.
It would suffice to use parens in the assignment, so that everybody is clear that fetchrow_array is being called in a list context:
The fact that you can get it to work in a scalar context at all is probably not important (except to the extent that this reveals bugs or inconsistencies in your particular DBD module). It's just better not to do it that way.while ( my ( $market ) = $market_sth->fetchrow_array ) { ... }
In reply to Re: Mysterious Code "DBI" - Why is this working?
by graff
in thread Mysterious Code "DBI" - Why is this working?
by awohld
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |