Re: if(wantarray){...}else{...}
- From: "Stumproot" <burlo.stumproot@xxxxxxxxx>
- Date: 11 Apr 2005 01:24:51 -0700
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.
.
- References:
- if(wantarray){...}else{...}
- From: Stumproot
- Re: if(wantarray){...}else{...}
- From: Tad McClellan
- if(wantarray){...}else{...}
- Prev by Date: Re: Basic Regular Expressions question...
- Next by Date: Simple Encryption Script
- Previous by thread: Re: if(wantarray){...}else{...}
- Next by thread: FAQ 3.18 How can I free an array or hash so my program shrinks?
- Index(es):