On Wed, May 08, 2013 at 10:58:02AM -0700, fe...@crowfix.com wrote:
> On Wed, May 08, 2013 at 09:43:27AM -0700, Bill Ward wrote:
> > Cool. That whole scalar vs list context thing is one of Perl's biggest
> > strengths, but also one of its biggest weaknesses (in that it is a common
> > source of bugs like this). When you see head-scratching problems, it's one
> > of the first things to look for.
> 
> Just guessing here, not familiar with the particular code in question.
> But I have been bitten a few times by code which returns false in the
> 'proper' manner
> 
>     return;
> 
> instead of forcing a scalar return
> 
>     return undef;
> 
> or list return
> 
>     return ();

There is no difference between "return;" and "return ();".
Both return an empty list when called in list context
and an undef when called in scalar context.

The "return ();" style does serve as a reminder to the reader.

> Is that what's going on here -- the original code imparted a list
> context, which triggered another perl gotcha, whereby missing list
> values simply disappear:
> 
>     scalar(1,2,,4,,6) ---> 4, not 6

That returns 6, or rather, it returns whatever happens to be the last value.

Tim.

Reply via email to