if(wantarray){...}else{...}



Posted from/using google news.



I have "return" snippets like this in several funktions
and I'm getting tired of writing them.

Is there a better way?


sub fun1 {
.
.
.
lots going on
.
.

# Start return snippet
if(wantarray) {
my @res = A_Funktion($a1,$a2);
return @res;
} else {
return A_Funktion($a1,$a2);
}
# End return snippet
}

sub fun2 {
.
.
.
lots going on
.
.

# Start return snippet
if(wantarray) {
my @res = Another_Funktion($a1,$a2);
return @res;
} else {
return Another_Funktion($a1,$a2);
}
# End return snippet
}


and several more...

.



Relevant Pages

  • neater way to phrase this
    ... neater or compact way of writing the following snippet? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: if(wantarray){...}else{...}
    ... > I have "return" snippets like this in several funktions ... > sub fun1 { ... > # Start return snippet ... Context is "see through". ...
    (comp.lang.perl.misc)