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


in reply to Re: Why does foo() evaluate in array context in "${\foo()}"?
in thread Why does foo() evaluate in array context in "${\foo()}"?

This is puzzling...

perlref says "Anywhere you’d put an identifier (or chain of identifiers) as part of a variable or subroutine name, you can replace the identifier with a BLOCK returning a reference of the correct type."

We can see from ELISHEVA's example that the sub is called in list context. I assume, therefore, that it returns a list. But a list isn't "a reference" even if every element of the list is. Is there an undocumented case of the block returning a list? Or am I wrong to think that the sub returns a list? If it doesn't return a list, what does it return and why?

Had the sub been called in scalar context then, because there is no such thing as a list in scalar context, what does \(LIST) become?

sub foo { \('fred', 'bill') };; print "${ scalar(foo()) }"; __END__ Returns: bill

So I know what happens in the end, but I'm having trouble reconciling my model of what perl does and what the various expressions mean.

update: Considering JavaFan's post I see my mistake: the sub is called in scalar context, not list context. The call is not the same as in ELISHEVA's original post. And perlref says \($a, $b, $c) is the same as (\$a, \$b, $\c). I conclude that in scalar context the latter is simply not a list.

update2: Changed "array context" to "list context" throughout, because that's what it is called.

update3: Clarified what perlref says and what I conclude/assume.