Re: if(wantarray){...}else{...}
- From: "A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 10 Apr 2005 21:26:28 GMT
"Stumproot" <burlo.stumproot@xxxxxxxxx> wrote in
news:1113167548.426110.231150@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
> Posted from/using google news.
Why is that relevant?
> I have "return" snippets like this in several funktions
> and I'm getting tired of writing them.
OK.
> Is there a better way?
I am not sure because I don't really understand what problem you are
attempting to solve.
> # Start return snippet
> if(wantarray) {
> my @res = A_Funktion($a1,$a2);
> return @res;
> } else {
> return A_Funktion($a1,$a2);
> }
Does A_Funktion behave differenly in scalar versus array context? If it
does not, then you shouldn't worry about wantarray.
#! /usr/bin/perl
my $r = A_Funktion(qw(Hello Goodbye));
my @r = A_Funktion(qw(Hello Goodbye));
print "$r\n@r\n";
sub A_Funktion_Caller {
A_Funktion(@_);
}
sub A_Funktion {
my ($x, $y) = @_;
"$x and $y";
}
__END__
On the other hand, is the following more like the situation above?
#! /usr/bin/perl
my $r = A_Funktion(qw(Hello Goodbye));
my @r = A_Funktion(qw(Hello Goodbye));
print "$r\n@r\n";
sub A_Funktion_Caller {
wantarray ? A_Funktion(@_) : scalar A_Funktion(@_);
}
sub A_Funktion {
my ($x, $y) = @_;
my $r = "$x and $y";
wantarray ? $r : length $r;
}
__END__
Please do read the posting guidelines posted here regularly. The
guidelines contain valuable information on how to help others help you.
Sinan
--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
.
- Follow-Ups:
- Re: if(wantarray){...}else{...}
- From: axel
- Re: if(wantarray){...}else{...}
- From: Stumproot
- Re: if(wantarray){...}else{...}
- From: A. Sinan Unur
- Re: if(wantarray){...}else{...}
- References:
- if(wantarray){...}else{...}
- From: Stumproot
- if(wantarray){...}else{...}
- Prev by Date: if(wantarray){...}else{...}
- Next by Date: Re: if(wantarray){...}else{...}
- Previous by thread: if(wantarray){...}else{...}
- Next by thread: Re: if(wantarray){...}else{...}
- Index(es):
Relevant Pages
|