Alien has asked for the wisdom of the Perl Monks concerning the following question:
andsub testc1 { if(defined wantarray()) { print "scalar\n"; } elsif(wantarray()) { print "array\n"; } else { print "void context\n"; } } testc1(); $a=testc1(); @a=testc1();
My question is : how come testc2 prints the right calling contexts but testc1 doesn't ?sub testc2 { if(wantarray()) { print "array\n"; } elsif(defined wantarray()) { print "scalar\n"; } else { print "void context\n"; } } $x=testc2(); @x=testc2(); testc2();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I check the return value of wantarray?
by imp (Priest) on Apr 04, 2007 at 15:09 UTC | |
|
Re: How do I check the return value of wantarray?
by mreece (Friar) on Apr 04, 2007 at 15:35 UTC | |
|
Re: How do I check the return value of wantarray?
by kyle (Abbot) on Apr 04, 2007 at 15:14 UTC | |
|
Re: How do I check the return value of wantarray?
by derby (Abbot) on Apr 04, 2007 at 15:32 UTC |