http://qs321.pair.com?node_id=608302


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();