RE: Name of IF style

This is a multipart message in MIME format.
--===============1110471606==
Content-Type: multipart/alternative;
boundary="=_alternative 004D8C558625727A_="

This is a multipart message in MIME format.
--=_alternative 004D8C558625727A_=
Content-Type: text/plain; charset="us-ascii"

Regarding your macro: "Ichiban, Taguchi-san!" Now, if I knew what the
editor was... I suspect it's a Japanese product, huh? (Guess the name gave
it away.)

If you go back to your Camel book (p.105 in my copy), you'll see that the
authors sort of deprecate the if-elsif-elsif-elsif-else structure. I've
had good success using a for statement (actually a single-pass loop) to
implement a switch structure, like this:

# ---------------------- code -----------------------
# assign value to $foo here, then...

for ($foo) {
/^abc/ && do {
$var = 'abc';
last; # required; prevents "fall-through"
};
/^def/ && do {
$var = 'def';
last;
};
/^ghi/ && do {
$var = 'ghi';
last;
};
# "default" handler goes here--the "else"
$var = 'oops!'
} # end of for structure
# ---------------------- code -----------------------

This structure is outlined right below the elsif-elsif-elsif thing. It's a
lot faster than all those elsifs strung together, also, a lot more
elegant. To speed things up even more, arrange the possibilities from
most-likely to least-likely, if such an order exists.

Best wishes,

Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150

"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
Babbage, if you put into the machine wrong figures, will the right answers
come out?' I am not able rightly to apprehend the kind of confusion of
ideas that could provoke such a question." -- Charles Babbage
--=_alternative 004D8C558625727A_=
Content-Type: text/html; charset="us-ascii"


<br><font size=2 face="sans-serif">Regarding your macro: "Ichiban, Taguchi-san!"  Now, if I knew what the editor was... I suspect it's a Japanese product, huh? (Guess the name gave it away.)</font>
<br>
<br><font size=2 face="sans-serif">If you go back to your Camel book (p.105 in my copy), you'll see that the authors sort of deprecate the if-elsif-elsif-elsif-else structure. I've had good success using a for statement (actually a single-pass loop) to implement a switch structure, like this:</font>
<br>
<br><font size=2 face="sans-serif"># ----------------------   code -----------------------</font>
<br><font size=2 face="sans-serif"># assign value to $foo here, then...</font>
<br>
<br><font size=2 face="sans-serif">for ($foo) {</font>
<br><font size=2 face="sans-serif">   /^abc/ && do {</font>
<br><font size=2 face="sans-serif">      $var = 'abc';</font>
<br><font size=2 face="sans-serif">      last;    # required; prevents "fall-through"</font>
<br><font size=2 face="sans-serif">   };</font>
<br><font size=2 face="sans-serif">   /^def/ && do {</font>
<br><font size=2 face="sans-serif">      $var = 'def';</font>
<br><font size=2 face="sans-serif">      last;</font>
<br><font size=2 face="sans-serif">   };</font>
<br><font size=2 face="sans-serif">   /^ghi/ && do {</font>
<br><font size=2 face="sans-serif">      $var = 'ghi';</font>
<br><font size=2 face="sans-serif">      last;</font>
<br><font size=2 face="sans-serif">   };</font>
<br><font size=2 face="sans-serif">   # "default" handler goes here--the "else"</font>
<br><font size=2 face="sans-serif">   $var = 'oops!'</font>
<br><font size=2 face="sans-serif">} # end of for structure</font>
<br><font size=2 face="sans-serif"># ----------------------   code -----------------------</font>
<br>
<br><font size=2 face="sans-serif">This structure is outlined right below the elsif-elsif-elsif thing. It's a lot faster than all those elsifs strung together, also, a lot more elegant.  To speed things up even more, arrange the possibilities from most-likely to least-likely, if such an order exists.</font>
<br>
<br><font size=2 face="sans-serif">Best wishes,</font>
<br><font size=2 face="sans-serif"><br>
Deane Rothenmaier<br>
Systems Architect<br>
Walgreens Corp.<br>
847-914-5150<br>
<br>
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage</font>
--=_alternative 004D8C558625727A_=--


--===============1110471606==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1110471606==--
Deane.Rothenmaier [ Di, 06 Februar 2007 15:07 ] [ ID #1621048 ]
Perl » gmane.comp.lang.perl.active-perl » RE: Name of IF style

Vorheriges Thema: Does perlapp have a problem with C:\Temp not there in WinXP boxes?
Nächstes Thema: Who does "MoveNext" belong to?