Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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
Domain Nodelet?
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 about the Monastery: (4)
As of 2023-03-20 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (59 votes). Check out past polls.

    Notices?