NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Perl::Critic (Score:1)
But I like it (Score:1)
I get a lot of milage out of implicit
return– I write many functions that consist of a single expression (disregarding parameter parsing), which read much nicer that way.Maybe precisely because I use it so purposefully, I am always keenly aware that subs always return something, and so when writing subs that aren’t supposed to, I usually put a bare
returnin there.Re: (Score:2)
Default behavior (Score:1)
Re: (Score:2)
Re: (Score:1)
I get what you are saying now.
It's not the subroutine, it's the block. (Score:1)
The fact that blocks return the last expression evaluated is what makes writing concise maps and greps.
Also note that whether a subroutine returns something or not is not determined by a return, or a last expression. Like anything else, it's determined by context. A subroutine will return nothing, if, and only if, it's called in void context. Otherwise, it will return something, even if it
Re: (Score:2)
process_lineto process a line of data. But I forgot that (somewhere in another file/class) that if process_line returns a scalar it gets sent to the client. It's hard to see that sort of thing in OO virtual APIs sometimes, but as everyone has rightly pointed out - it was programmer error.Doesn't mean I think "use strict 'return'" is any less of a good idea though.
Re: (Score:2)
-Dom