develooper Front page | perl.perl5.porters | Postings from June 2008

Re: [perl #56150] return return

Thread Previous | Thread Next
Mark Mielke
June 23, 2008 07:18
Re: [perl #56150] return return
Message ID:
H.Merijn Brand wrote:
>> sub NAME
>> {
>>     ... lots of code ...
>>     undef;
>> }
> What if the function can return a list or a scalar? "return" handles
> that automatically, undef does not;

Hehe - good question. My answer is that it tends not to happen for my 
style of programming. That is, a function that returns a list would take 
the form:

sub NAME
    my @results;

    ... do whatever to @results ...


Now, I do recall it happening once in the past where I found the need to 
return from @results from inside a conditional - and I think I decided 
on "return ();" as I found "return;" to not communicate "return an empty 
list" as explicitly as I wanted. It was an imperfect situation. :-(

> BTW I agree with both worlds. In some cases it should suffice to use
> the last value, in some cases one should use return for clarity

Agree. I was playing devil's advocate - not intending to say "never ever 
use return!". I only challenged the claim that one should "always use 
return!". :-) It came across as dogma like "never use goto!". :-)


Mark Mielke <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About