"be consistent" | |
PerlMonks |
Re^3: Module Announcement: Perl-Critic-1.01by Rhandom (Curate) |
on Jan 26, 2007 at 19:32 UTC ( [id://596775]=note: print w/replies, xml ) | Need Help?? |
You are correct. I can't argue that that is what happens when you return undef.
Now - the larger question is, who is still designing Perl module interfaces that return non-scalar results. I can't remember the last time I designed a function to return a list of values - much less variably return a list or a single scalar depending upon context. To me it is a code smell to not return a single scalar value (the single value could be arrayref or hashref - but it is still a single value). I know that may not sound Perlish - but as a user of the modules I produce I prefer not have to guess what context I need to call items in. It also saves memory to return arrayrefs or hashrefs. Yes I still use map and grep and caller and times and stat, but they are some of the last things I use that return lists. Perl 6 will fix some of these issues.
my @a=qw(random brilliant braindead); print $a[rand(@a)];
In Section
Meditations
|
|