Ronald J Kimball [EMAIL PROTECTED] wrote:
> On Tue, Jun 24, 2003 at 03:42:16PM -0400, Hardy Merrill wrote:
> > From 'perldoc DBI':
> > 
> >        "fetchrow_array"
> >             @ary = $sth->fetchrow_array;
> >  
> >            An alternative to "fetchrow_arrayref". Fetches the next row of data
> >            and returns it as a list containing the field values.  Null fields
> >            are returned as "undef" values in the list.
> > 
> > Notice that you are accepting the results of $sth->fetchrow_array
> > into a *scalar* $sr_id - using fetchrow_array that should be
> > an array.  When you use a scalar in list context, the scalar
> > ends up containing the *number* of array elements.
> 
> Don't confuse an array in scalar context with a function call in scalar
> context.  A function call in scalar context could return the number of
> elements, or the first element, or a ref to an array of elements, or
> something else; it's up to the author of the function.
> 
> In this case, the behavior of fetchrow_array() in a scalar context is
> undefined:
> 
>            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.

Thanks for catching that Ronald - my bad :-/

Hardy

Reply via email to