Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Why does foo() evaluate in array context in "${\foo()}"?by repellent (Priest) |
on Apr 23, 2009 at 19:00 UTC ( [id://759628]=note: print w/replies, xml ) | Need Help?? |
The way I see it, ${ EXPR1 } forces scalar context and then performs a scalar dereference on EXPR1. The backslash \( EXPR2 ) forces list context on EXPR2 and returns a list of references. By combining the two, you have \foo() returning a list of one reference to scalar 10. Then, ${ (\10) } returns the scalar dereferenced 10. FYI, there's a catch to using the \( ) syntax for @arrays:
Update: BTW, same catch applies to %hashes.
In Section
Seekers of Perl Wisdom
|
|