|
This is a nice one that I forgot to put in the class.
People like to write return undef
to make a function that returns a false value,
but this is often wrong, because in list context,
return undef returns true.
(It returns a list with a single undefined element.
But only an empty list is false.)
Some programmers are aware of this problem, and write
return wantarray ? () : undef; which works,
but is unnecessarily complicated.
The best answer here is to simply write return;
which returns an undefined scalar value in scalar context,
and an empty list in list context.
|