Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Non-local return via last()

by tobyink (Abbot)
on Sep 27, 2012 at 12:37 UTC ( #996001=note: print w/replies, xml ) Need Help??

in reply to Non-local return via last()

Nice. I've been looking for a solution for a while for resolving this disparity:

use 5.010; use List::Util qw(first); sub sub1 { first { return 1 } @_; return 2; } sub sub2 { grep { return 1 } @_; return 2; } say sub1(0); say sub2(0);

Given that first and grep are conceptually similar, it is counter-intuitive that return inside them means different things. While prototypes help first look like a built-in list operator, they don't help it act like one.

I've played around with Scope::Upper a little to try to come up with a resolution for this, but haven't had any luck so far. (Though as a by-product I managed to come up with returning which is pretty fun.) I wonder if last might provide some kind of solution.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996001]
marioroy At a large firm, had to awaken a security guy a few times so that nobody would catch him sleeping.
marioroy On a large dairy farm, almost went off the road with a 10 wheeler from exhaustion. On the farm, almost went off the silo with a big tractor. At the Fransiscan monastery, almost slipped off the dome while painting it.
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.
Lady_Aleena clean up after dinner finally.
[Discipulus]: uch! so we are twice lucky to have MCE..;=)
[marioroy]: Working a midnight graveyard shift, on the way home ran out of gas. just 2 minutes later somebody stops with a small tank of gas. It's wierd. There's always someone nearby for some reason.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-05-29 08:22 GMT
Find Nodes?
    Voting Booth?