in reply to Re: Hope a subroutine will return undef by default
in thread Hope a subroutine will return undef by default
From above cert.org link ...
In list context, things are slightly more complicated. An empty list, when evaluated in a boolean condition, evaluates to false. But the value undef, when evaluated in list context, evaluates to true because it is converted to a list with the singleton value undef. Therefore, a function should not return undef if it might ever be invoked in list context.
... that very thing -- an empty list collapsing to nothing -- has caused me irritation to work around it when something is expected, even undef: by calling the offending code in scalar context. And that was/is the *only* purpose of that damn separate call. I absolutely hate context based returned values in such cases.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Hope a subroutine will return undef by default ("boolean list context")
by tye (Sage) on Feb 12, 2014 at 03:42 UTC |