[Phoenix-pm] given/when in Perl 5

Michael Friedman friedman at highwire.stanford.edu
Sun Mar 12 17:05:00 PST 2006


I thought "Perl doesn't need a case statement"?
Or is this Perl 6 getting implemented in Perl 5 just because they can...

-- Mike

On Mar 12, 2006, at 12:36 AM, Scott Walters wrote:

> 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
>
> _______________________________________________
> Phoenix-pm mailing list
> Phoenix-pm at pm.org
> http://mail.pm.org/mailman/listinfo/phoenix-pm

---------------------------------------------------------------------
Michael Friedman                     HighWire Press
Phone: 650-725-1974                  Stanford University
FAX:   270-721-8034                  <friedman at highwire.stanford.edu>
---------------------------------------------------------------------




More information about the Phoenix-pm mailing list