in reply to Re^3: Perl Style: Is initializing variables considered taboo?
in thread Perl Style: Is initializing variables considered taboo?
and please be careful not to return undef to "explicitly" return false.Many people use return undef to indicate false in the execution of a sub, but it's likely I'm really not getting what you mean by "explicitly":
perl -e 'foreach (@INC){print "$_\n" unless $_ eq q{.}}' | xargs grep +-R "return undef" | wc -l<br> 1752
Subs return lists, so what you are actually doing is returning a one-element list instead of an empty one. I.e. @array=func(); Using a blank return is the same like return (); and won't byte you in list context but in scalar context the variable will be undef anyway.I have found it wise to always return an explicit value, to avoid a potential bite or 'feature' of the "last expression", and have till now, used undef to indicate falseness and failure, and a defined value or "1", to indicate trueness/success.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Perl Style: Is initializing variables considered taboo?
by chromatic (Archbishop) on Aug 23, 2010 at 00:24 UTC | |
|
Re^5: Perl Style: ... (TRUE, FALSE and FAILED)
by LanX (Saint) on Aug 23, 2010 at 10:08 UTC | |
by ait (Hermit) on Aug 25, 2010 at 00:32 UTC |