[Phoenix-pm] given/when in Perl 5

Scott Walters scott at illogics.org
Sun Mar 12 21:59:28 PST 2006


Hey Michael,

Perl "doesn't need" a lot of things... named parameters, strong type
checking, etc... of course, you don't *need* anything more than a 
some toggle switches to toggle in machine code... but certain things
at certain times are nice to have.  In this case, switch (no pun
intended) has been in the todo since the early days (reportedly),
but there were too many scenarios to consider so it never got done.
Damian Conway made a pass at the problem with Switch.pm, this got
adopted in a modified form into Perl 6's design documents, and then
that official-making-ness was enough to get it cleared for Perl 5.
Funny how these things work...

Cheers!  Good to see you around on the list by the way =)

-scott

On  0, Michael Friedman <friedman at highwire.stanford.edu> wrote:
> 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>
> ---------------------------------------------------------------------
> 
> 
> _______________________________________________
> Phoenix-pm mailing list
> Phoenix-pm at pm.org
> http://mail.pm.org/mailman/listinfo/phoenix-pm


More information about the Phoenix-pm mailing list