<?xml version="1.0" encoding="windows-1252"?>
<node id="996001" title="Re: Non-local return via last()" created="2012-09-27 08:37:18" updated="2012-09-27 08:37:18">
<type id="11">
note</type>
<author id="757127">
tobyink</author>
<data>
<field name="doctext">
&lt;p&gt;Nice. I've been looking for a solution for a while for resolving this disparity:&lt;/p&gt;

&lt;code&gt;
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);
&lt;/code&gt;

&lt;p&gt;Given that &lt;c&gt;first&lt;/c&gt; and &lt;c&gt;grep&lt;/c&gt; are conceptually similar, it is counter-intuitive that &lt;c&gt;return&lt;/c&gt; inside them means different things. While prototypes help &lt;c&gt;first&lt;/c&gt; &lt;em&gt;look&lt;/em&gt; like a built-in list operator, they don't help it &lt;em&gt;act&lt;/em&gt; like one.&lt;/p&gt;

&lt;p&gt;I've played around with [mod://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 [mod://returning] which is pretty fun.) I wonder if &lt;c&gt;last&lt;/c&gt; might provide some kind of solution.&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-757127"&gt;
&lt;small&gt;&lt;small&gt;
&lt;tt&gt;perl -E'sub Monkey::do{say$_,for@_,do{($monkey=&amp;#x5B;caller(0)]-&gt;&amp;#x5B;3])=~s{::}{ }and$monkey}}"Monkey say"-&gt;Monkey::do'
&lt;/tt&gt;&lt;/small&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
995995</field>
<field name="parent_node">
995995</field>
</data>
</node>
