Empty Hash Values
dave at dave.org.uk
Tue Apr 14 22:02:53 BST 2009
Dave Hodgkinson wrote:
> On 14 Apr 2009, at 18:16, Matt Lawrence wrote:
>> Jasper wrote:
>>> Adrian and I had a tiny chat about this in work, and he decided that
>>> subs that return a scalar should return undef explicitly (if they are
>>> just returning), and those that return a list should return.
>>> At the time I thought it seemed very sensible, but I'm on the fence
>>> Difficult to retroactively enforce, at any rate.
>> Most of the time just returning does what you expect, it's false in
>> every context and undef in scalar context.
> And fails PBP for exactly the confusion in previous mails. Plain
> return is Just Wrong. Be explicit.
PBP disagrees with you.
9.12. Returning Failure
Use a bare return to return failure.
Notice that each final return statement in the examples of the
previous guideline used a return keyword with no argument, rather
than a more-explicit return undef.
Normally, relying on default behaviour is not best practice. But in
the case of a return statement, relying on the default return value
actually prevents a particularly nasty bug.
The problem with returning an explicit return undef is that—contrary
to most people's expectations—a returned undef isn't always false.
More information about the london.pm