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();
In reply to How do I check the return value of wantarray? by Alien
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |