in reply to Re^2: wantarray - surprise behaviour
in thread wantarray - surprise behaviour

Wnatarray()s return is always the context of the call of the subroutine that it is in. Note also that wantarray always returns a scalar value (0, 1, undef)

What happens inside the subroutine that wantarray() is in is absolutely irrelevant to what wantarray() reports.

There are 3 contexts that a subroutine can be called in:

blah(); # void $x = blah(); # scalar @x = blah(); # list
Anything you can dream up that can be assigned into fits into one of those categories. But dont trick yourself into thinking something like this will try a list assignment:
my $x = []; # $x is now an (empty) arrayref $x = blah(); # $x is a scalar - wantarray reports 0
So, even though $x is an arrayref, an arrayref is NOT a list, its a scalar. A reference to be specific.