[Phoenix-pm] given/when in Perl 5

Scott Walters scott at illogics.org
Sun Mar 12 00:36:34 PST 2006


Hi happy Perl people,

Here's a cut and paste from the perldoc perlsyn from 5.9.3:

           use feature ":5.10";
           given($foo) {
               when (undef) {
                   say '$foo is undefined';
               }

               when ("foo") {
                   say '$foo is the string "foo"';
               }

               when ([1,3,5,7,9]) {
                   say '$foo is an odd digit';
                   continue; # Fall through
               }

               when ($_ < 100) {
                   say '$foo is numerically less than 100';
               }

               when (\&complicated_check) {
                   say 'complicated_check($foo) is true';
               }

               default {
                   die q(I don't know what to do with $foo);
               }
           }

Muahahahahah!

-scott



More information about the Phoenix-pm mailing list