in reply to Re^3: regexp list return 5.6 vs 5.8
in thread regexp list return 5.6 vs 5.8
Assignment is a little bit special in that it uses its left argument to determine the context for the right argument. Assignment to a scalar evaluates the right-hand side in scalar context, while assignment to an array or hash evaluates the righthand side in list context. Assignment to a list (or slice, which is just a list anyway) also evaluates the righthand side in list context.
Then there's perlop which states that qw generates a real list at compile time, and returns the last element of that in scalar context (which AFAIK is resolved at runtime). Array slices seem to work the same way (compile time list construction).
But that either
- shouldn't be the case with subroutine returns, according to the docs, or
- should be documented in the docs, like, "Subroutines return lists, except when they don't. Aggregates are returned as flattened lists, but lists are evaluated in the caller's context".
Subroutine return values are evaluated in the caller's context on return, they are not made into a list context on exit which is then evaluated in the caller's context. This is arguably a feature...
Thanks for bringing that up.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}