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


in reply to Re^2: regexp list return 5.6 vs 5.8
in thread regexp list return 5.6 vs 5.8

Subroutines return a list of scalars, but when the sub is in scalar context, that list will always have exactly one scalar in it.

"A 'return' statement [...] will be evaluated in the appropriate context" means the op which returns the arguments to return is executed in the same context as the sub. It's the *statement* that is evaluated in the appropriate context, not the values returned.

When evaluated in scalar context, arrays return their length. (Case 1)
When evaluated in scalar context, lists return their last element. (Case 3)
When evaluated in scalar context, list assignments return the number of elements assigned. (Case 2 and 4)