Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How do I check the return value of wantarray?

by mreece (Friar)
on Apr 04, 2007 at 15:35 UTC ( #608302=note: print w/replies, xml ) Need Help??


in reply to How do I check the return value of wantarray?

as this demonstates, wantarray is defined in both scalar and list context (which is why your testc1 fails), but true only in list context.
sub testc { if (defined wantarray() and not wantarray()) { print "scalar\n"; } elsif (defined wantarray() and wantarray()) { print "array\n"; } elsif (not defined wantarray()) { print "void\n"; } } my $x = testc(); my @x = testc(); testc();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://608302]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2021-01-18 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?