Empty Hash Values

Adrian Lai perl at loathe.me.uk
Tue Apr 14 22:08:50 BST 2009

2009/4/14 Dave Hodgkinson <davehodg at gmail.com>:
> On 14 Apr 2009, at 18:16, Matt Lawrence wrote:
>> 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.

This isn't actually what PBP (or at least, the book of that name)
says, and is subject to one or two "discussions" I've had at my
current place of work.

The book states; "Use a bare return to return failure" [0].
My standpoint has always quite firmly been that the calling code
should be aware of the context in which to call the function in
question, and that bare returns aren't the bestest of ideas.

Whilst I accept the argument that "if (my @list = myfunction()) { ...
}" could cause issues if myfunction() returns undef, this shouldn't be
a real issue if myfunction() is always expected to return a scalar
And as has been illustrated, there are other problems inherent with
bare returns - I suppose it's a matter of debate as to which is the
lesser evil.

Right now, I'm sorta standing by my opinion that if something is
supposed to return a list, it should return the empty list in case of
failure, and if it's supposed to return a scalar, then undef.


[0] http://my.safaribooksonline.com/0596001738/perlbp-CHP-9-SECT-12

More information about the london.pm mailing list