Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: regexp list return 5.6 vs 5.8

by ikegami (Pope)
on Jan 24, 2008 at 18:29 UTC ( #664110=note: print w/replies, xml ) Need Help??

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)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://664110]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2020-10-24 01:39 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (242 votes). Check out past polls.