Toby,<div><br></div><div>I've noticed this. It'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 'parsefail on each(... ; ...)'</div><div> {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span># simple example L<S04/"Switch statements" /You don't have to use an explicit default/></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>for each(("T", "E", 5) ; (10, 11, 5)) -> $digit, $expected {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> my $result_a = do given $digit {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>when "T" { 10 }</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>when "E" { 11 }</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$digit</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> };</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> my $result_b = do given $digit {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>when "T" { 10 }</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>when "E" { 11 }</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>default { $digit }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> };</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> is($result_a, $expected, "result of $digit using implicit default {} is $expected");</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> is($result_b, $expected, "result of $digit using explicit default {} is $expected");</div>
<div><span class="Apple-tab-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 & 5.</div>
<div><br></div><div>I would've thought that Perl 5 should behave the same way. Also it wouldn't hurt to back-port the 'given' tests from rakudo.</div><div>- David</div><div><br><div class="gmail_quote">On Wed, Jun 2, 2010 at 3:16 PM, Toby Corkindale <span dir="ltr"><<a href="mailto:toby.corkindale@strategicdata.com.au">toby.corkindale@strategicdata.com.au</a>></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'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>