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



Tad McClellan wrote:
> Stumproot <burlo.stumproot@xxxxxxxxx> wrote:
>
> > Posted from/using google news.
> What is the relevance of including that?
Somtimes google does funny things with formatting of replies and I
thought it would be nice to warn people I'm using a less than ideal way
to post.

<snip code and commets re wantarray>

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


This I did not know, very handy.
Thanks.

.