Posted from/using google news.
What is the relevance of including that?
I have "return" snippets like this in several funktions
and I'm getting tired of writing them.
Is there a better way?
Is there a better way to what?
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
}
I have no idea why are you doing this.
If A_Funktion() is written to be used in either context, then
the wantarray() checking would be inside of A_Funktion()'s
declaration rather than wrapped around every call to A_Funktion().
No wonder you're getting tired.
Context is "see through". In the code below, A_Funktion() sees
whatever context fun1() got called in.
-----------------------------
#!/usr/bin/perl
use warnings;
use strict;
my $scalar = fun1();
my($list) = fun1();
my($a1,$a2);
sub fun1 {
# lots going on...
return A_Funktion($a1,$a2);
}
sub A_Funktion {
if(wantarray) {
warn "A_Funktion() in list context\n"
} else {
warn "A_Funktion() in scalar context\n"
}
}