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.
|
|---|