[Phoenix-pm] given/when in Perl 5

Metz, Bobby W, WCS bwmetz at att.com
Mon Mar 13 07:48:36 PST 2006


Aside from the fact that given/when is easier to read, why those names
instead of case?  If I were a "case language" guy moving to Perl and
looking for a case equivalent, I wouldn't think to search for those
words in my handy-dandy Perl book index.  I'll just assume it has a good
cross-index I suppose.

B

-----Original Message-----
From: phoenix-pm-bounces+bwmetz=att.com at pm.org
[mailto:phoenix-pm-bounces+bwmetz=att.com at pm.org]On Behalf Of Scott
Walters
Sent: Sunday, March 12, 2006 10:59 PM
To: Michael Friedman
Cc: phoenix-pm at pm.org
Subject: Re: [Phoenix-pm] given/when in Perl 5


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
_______________________________________________
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