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



"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
.



Relevant Pages

  • Need help Cleaning up Code
    ... have used the recorder and snippets of code I've found to create the ... Sub Cleanup_Convert ... 'This Adds the Planned Column ...
    (microsoft.public.excel.programming)
  • Re: newbie baffled by de/referencing with subroutines
    ... > and I want to use data from that array after the sub is finished. ... The guidelines contain valuable information on how to help others help ... scope of the subroutine. ...
    (comp.lang.perl.misc)
  • RE: How do I debug in the VBA window?
    ... functions some brief guidelines can be found at ... Handling section. ... In you error handler include the source. ... IE include the sub name such as ...
    (microsoft.public.access.modulesdaovba)
  • Re: Hash
    ... IIRC, you have already posted ... and you ought to know about the guidelines. ... sub make_prompt { ...
    (comp.lang.perl.misc)
  • Re: if(wantarray){...}else{...}
    ... Please note the corrections below. ... > sub A_Funktion_Caller { ... comp.lang.perl.misc guidelines on the WWW: ... Prev by Date: ...
    (comp.lang.perl.misc)