SPUG: while question
ced at carios2.ca.boeing.com
ced at carios2.ca.boeing.com
Tue Sep 16 13:41:16 CDT 2003
> while ($MyData = $sth->fetchrow())
> {
> stuff
> }
>
> This falls down when the data returned from the statement is '0', since
> it's not true, and the while breaks. I've tried while (defined $MyData =
> $sth->fetchrow()), but this is not syntacticly correct, and would break on a
> database NULL (which is undef in perl) anway. I can do something like while
> ($MyRef = $sth->fetchrow_hashref()) {$MyData = $$MyRef{datapoint}; stuff},
> but I'm not too fond of that. Does anyone have a suggestion on a better way
> to construct this loop?
I'm not sure why fetchrow_hashref doesn't make the cut but
you could fetch the list rather than the scalar:
while ( ($item) = fetchrow_array() ) {
In general, though, this'll still be slower than just returning a ref.
with fetchrow_hashref() or fetch().
--
Charles DeRykus
More information about the spug-list
mailing list