![]() |
|
Syntactic Confectionery Delight | |
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
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?
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. In reply to Re^2: Why does foo() evaluate in array context in "${\foo()}"?
by ig
|
|