[Melbourne-pm] Perl switch statements

Toby Corkindale toby.corkindale at strategicdata.com.au
Sun Oct 21 22:51:26 PDT 2012


On 22/10/12 16:36, Toby Corkindale wrote:
> Something bugs me about Perl's switch statements.
>
> If you put a given(){} block at the end of a function, the function will
> return the matched result. However if you attempt to assign the result
> of given() directly to a variable, it will fail.
>
> Who came up with this and what were they thinking? I suppose there's a
> good reason, but I can't see what it is.
 > [snip example]


I suppose it's consistent to other control syntax, eg.

sub foo {
   my $thing = shift;
   if ($thing eq 'ay') { "yay" }
   else { "boo" }
} 
          say foo("ay");
# outputs: yay

but that still bothers me.. Why is the result good enough to return but 
not to assign?


More information about the Melbourne-pm mailing list