[ABE.pm] perl 5.10 rules! - a switch statement

Ted Fiedler fiedlert at gmail.com
Mon Jun 4 04:36:09 PDT 2007


>
>
> ...but how about some additional awesome magic?


Who doesn't like magic? :)


  given ($variable) {
>     when (1) { # $variable == 1
>       do_something_one;
>     }
>
>     when (@edge_cases) { # if $variable in @edge_cases
>       do_edge_case_handler;
>     }
>
>     when ($_ > 10e6) { # if $variable is over a million
>       do_huge_handler;
>     }
>
>     when (\&test) { # if test($_) is true
>       say "the test was true!";
>       continue;
>     }
>
>     default {
>       default_handler;
>     }
>   }


Regex?

___SNIP___

when ( /^\Q$somepattern\E$/)
{
  say "seen $somepattern"
}

___SNIP___




-- 
"You are never dedicated to something you have complete confidence in. No
one is fanatically shouting that the sun is going to rise tomorrow. They
know it's going to rise tomorrow. "
  -- Robert M Pirsig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/abe-pm/attachments/20070604/5db5ab5b/attachment.html 


More information about the ABE-pm mailing list