[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] testing



The given code is

> if ($value == $a or $value == $b or  $value == $c or $value == $d or ...)

and not if..elsif..elsif, which lends itself to a "switch" type construct.
In C we can have multiple cases perform a single action, because of the
"fall through" nature of the switch construct, but none of the switch
examples address this particular situation.  I would like, with great
interest, to see a perl "switch" that addresses this particular situation.

When I first saw the "switch" technique implemented, I found it rather
difficult to follow.  Intuitive, they are not.  I would bargain to say that
the construct was invented by Perl apologists for the benefit of veteran C
programmers (as a native perl contruct was apparently "overlooked" when it
was invented).  And its usefulness pretty much begins and ends there.  At
this stage it has become one of those peculiar constructs like $var||=1 that
are of limited usefulness but make perl programmers feel "cool" when they
use them.

The construct most readable and apt to maintain program logic is the if(
expr or expr or expr ...) or if..elsif..else, but unfortunately those
constructs are not "cool".

-K

"A foolish consistency is the hobgoblin of little minds"

> From: "ehughes" <ehughes@novapic.org>
> Date: Wed, 15 Dec 1999 08:33:10 -0800
> To: Ken Williams <ken@forum.swarthmore.edu>, Arved Sandstrom
> <Arved_37@chebucto.ns.ca>
> Cc: "Nicholas G. Thornton" <Nicholas.G.Thornton@directory.reed.edu>,
> macperl@macperl.org
> Subject: Re: [MacPerl] testing
> 
>> From: Ken Williams <ken@forum.swarthmore.edu>
> 
>> And what "switch" construct is that?  There is none in Perl.
> 
> Hi Guys,
> 
> While I am not speaking for Arved, (he know a whole lot more about Perl than
> I do), I suspect this is what he was talking about.
> 
> From the Camel Book, page 104,
> 
> SWITCH: {
> if (/^abc) { $abc =1; last SWITCH;}
> if (/^def) { $def =1; last SWITCH;}
> if (/^xyz) { $xyz =1; last SWITCH;}
> $nothing = 1;
> }
> 
> Or maybe this version,
> 
> SWITCH: {
> $abc = 1, last SWITCH if /^abc/;
> $def = 1, last SWITCH if /^def/;
> $xyz = 1, last SWITCH if /^xyz/;
> $nothing = 1;
> }
> 
> There are four other examples listed. I agree with Arved on one point. Keep
> it simple and straightforward. Reading code 6 months later can be a little
> embarrassing with some of Perl's more unique constructs.
> 
> Elton
> 
> =========================================================================
> NOVA Private Industry Council                 505 W. Olive Ave. Suite 550
> Elton Hughes (Information Technology)                  Sunnyvale CA 94086
> Phone: 408-730-7235                                     Fax: 408-730-7643
> -------------------------------------------------------------------------
> 
> 
> # ===== Want to unsubscribe from this list?
> # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org
> 


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org