What is also surprising is this:<div><br></div><div><div>sub moo {</div><div>  given (shift) {</div><div>    when ('ay') { "yay" }</div><div>    when ('bee') { "hurrah" }</div><div>    default { "what?" }</div>

<div>  };</div><div>  say $_;</div><div>}</div><div>moo("bee");</div><div><br></div><div><br></div><div>I thought the when() implemented the test against $_... </div><div><br>or even:</div><div><br></div><div><div>

sub moo {</div><div>  given (shift) {</div><div>    when ('ay') { "yay" }</div><div>    when ('bee') { $_ = "hurrah" }</div><div>    default { "what?" }</div><div>  };</div><div>

  say $_;</div><div>}</div><div>moo("bee");</div></div><div><br></div><div><br></div><div><br><div class="gmail_quote">On 22 October 2012 16:39, Toby Corkindale <span dir="ltr"><<a href="mailto:toby.corkindale@strategicdata.com.au" target="_blank">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"><div class="im">On 22/10/12 16:36, Toby Corkindale wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Something bugs me about Perl's switch statements.<br>
<br>
If you put a given(){} block at the end of a function, the function will<br>
return the matched result. However if you attempt to assign the result<br>
of given() directly to a variable, it will fail.<br>
<br>
Who came up with this and what were they thinking? I suppose there's a<br>
good reason, but I can't see what it is.<br>
<br>
Compare these:<br>
------------------------------<u></u>---------<br>
<br>
sub foo {<br>
   given (shift) {<br>
     when ('ay') { "yay" }<br>
     when ('bee') { "hurrah" }<br>
     default { "what?" }<br>
   }<br>
}<br>
say foo("bee");<br>
# outputs: hurrah<br>
<br>
------------------------------<u></u>---------<br>
<br>
sub bar {<br>
   say given (shift) {<br>
     when ('ay') { "yay" }<br>
     when ('bee') { "hurrah" }<br>
     default { "what?" }<br>
}<br>
</blockquote>
<br></div>
Oops.<br>
My copy of the function above is missing the final closing curly brace. It still doesn't work with it though, but you get a different error.<div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<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/<u></u>listinfo/melbourne-pm</a><br>
</div></div></blockquote></div><br></div></div>