"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
After giving what I believed to be a complete answer yesterday, I realized that it still wasn't quite correct.
It is true that subroutines return lists not arrays, but
when called in scalar context they dont necessarily return the scalar value of that list.
The most obvious example of this is localtime() whose return values in scalar and list context have little to do with one another. Another example happens to be fetchrow_array() From the DBI pod: In a scalar context, fetchrow_array returns the value of the first field. An undef is returned if there are no more rows or if an error occurred. Since that undef can't be distinguished from an undef returned because the first field value was NULL, you should exercise some caution if you use fetchrow_array in a scalar context.Using my logic, in scalar context we'd get the last field not the first. The moral of the story is that the behavior of a subroutine in scalar context can't be determined from its list context return value. Here are three subs that return the same values in list context, but behave differently in scalar context:
-Blake In reply to Re4: MySQL / Perl Question
by blakem
|
|