MESSAGE
DATE | 2004-11-20 |
FROM | Billy
|
SUBJECT | Re: [hangout] Perl vs. PHP
|
Ruben Safir wrote:
> > >> The immediate context was the (current) lack of a >>case/switch construct in Perl... about which I never understood >>why it is such a big deal. >> >> >> > >The control flow is so flexible in perl that it doesn't need a case >statement. > >Their an idiot. > > I don't think so. I think it should have a case statement.
One of the nice things about Perl is how little you need to write to express the most common sorts of routines. Considering how easy it is to slurp through lines of input files (for example), it's surprisingly hard to write a proper case statement without any bugs, IMHO.
Flexibility isn't always what I want. I want to express my decision tree without jumping through any flaming hula-hoops.
The absence of a switch (or case) statement has always seemed contrary to Perl's (learning-curve reducing) mimicry of C and sh. Which would you rather do?
for($expr){ /^0$/ and do { foostuff; last} /^1$/ and do { barstuff; last} do { defaultstuff; last } }
Or:
switch($expr){ case 0: foostuff; break; case 1: barstuff; break; default: defaultstuff; break; }
I like the second one... fewer keywords, and you're not abusing 'for', 'and', or 'last'. ____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|