Hi Toby,<div><br></div><div>I had a look at the latest perl 5.13.1. Someone&#39;s just fixed it!</div><div><br></div><div>From  perl5131delta.pod:</div><div><br></div><div><div>   &quot;given&quot; return values</div><div>
       Starting from this release, &quot;given&quot; blocks returns the last evaluated</div><div>       expression, or an empty list if the block was exited by &quot;break&quot;. Thus</div><div>       you can now write:</div>
<div><br></div><div>           my $type = do {</div><div>            given ($num) {</div><div>             break     when undef;</div><div>             &#39;integer&#39; when /^[+-]?[0-9]+$/;</div><div>             &#39;float&#39;   when /^[+-]?[0-9]+(?:\.[0-9]+)?$/;</div>
<div>             &#39;unknown&#39;;</div><div>            }</div><div>           };</div><div><br></div><div>       See &quot;Return value&quot; in perlsyn for details.</div></div><div><br></div><div>Cheers</div><div>- David<br>
<br><div class="gmail_quote">On Thu, Jun 3, 2010 at 8:17 AM, David Warring <span dir="ltr">&lt;<a href="mailto:david.warring@gmail.com">david.warring@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Toby,<div><br></div><div>I&#39;ve noticed this. It&#39;s supposed to be a back-port of a Perl 6 feature.</div><div><br></div><div>I grokked the Perl 6 test suite and fond the following in t/spec/S04-statements/given.t</div>

<div><br></div><div>==================================</div><div><div>    # from apocalypse 4</div><div>    #?rakudo skip &#39;parsefail on each(... ; ...)&#39;</div><div>    {</div><div><span style="white-space:pre">        </span># simple example L&lt;S04/&quot;Switch statements&quot; /You don&#39;t have to use an explicit default/&gt;</div>

<div><span style="white-space:pre">        </span>for each((&quot;T&quot;, &quot;E&quot;, 5) ; (10, 11, 5)) -&gt; $digit, $expected {</div><div><span style="white-space:pre">        </span>    my $result_a = do given $digit {</div>
<div><span style="white-space:pre">                </span>when &quot;T&quot; { 10 }</div><div><span style="white-space:pre">                </span>when &quot;E&quot; { 11 }</div><div><span style="white-space:pre">                </span>$digit</div>
<div><span style="white-space:pre">        </span>    };</div><div><br></div><div><span style="white-space:pre">        </span>    my $result_b = do given $digit {</div><div><span style="white-space:pre">                </span>when &quot;T&quot; { 10 }</div>

<div><span style="white-space:pre">                </span>when &quot;E&quot; { 11 }</div><div><span style="white-space:pre">                </span>default  { $digit }</div><div><span style="white-space:pre">        </span>    };</div>
<div><br></div><div><span style="white-space:pre">        </span>    is($result_a, $expected, &quot;result of $digit using implicit default {} is $expected&quot;);</div><div><span style="white-space:pre">        </span>    is($result_b, $expected, &quot;result of $digit using explicit default {} is $expected&quot;);</div>

<div><span style="white-space:pre">        </span>}</div><div>    }</div></div><div>===================================</div><div><br></div><div>So it looks as if this is inconsistently implemented across Perl 6 &amp; 5.</div>
<div><br></div><div>I would&#39;ve thought that Perl 5 should behave the same way. Also it wouldn&#39;t hurt to back-port the &#39;given&#39; tests from rakudo.</div><div>- David</div><div><div></div><div class="h5"><div>
<br><div class="gmail_quote">On Wed, Jun 2, 2010 at 3:16 PM, Toby Corkindale <span dir="ltr">&lt;<a href="mailto:toby.corkindale@strategicdata.com.au" target="_blank">toby.corkindale@strategicdata.com.au</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">An annoyance right now is that the given/when syntax does not return the values in the code block executed, so you can&#39;t use them inside grep,etc.<br>


<br>
Has anyone else noticed a way around that? (Apart from wrapping it in an anonymous subroutine and then returing out of the when blocks)<br>
_______________________________________________<br>
Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>