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

Re: [MacPerl] & Usage and Misc. ?'s



About the ?: usage and order of action(?)

You might often overhear "let's do this unless this occurs"
or you might hear "unless so and so do this step".
Both are correct, yet ephasize different aspects of the same problem.

I have only been 'exposed' to this notation in the past year,
but  more and more I tend to use it over a simple "if/elsif/else"
for clarity. Mind you, this is just a preference, but I think it
is good logic in a march toward a 5GL language.

Here's a simple example of a cascading ?: structure.

$sentenceEnding =
($type eq 'question')         ? 'question mark' :
($type eq 'demand')           ? 'exclamation point' :
($type eq 'explecitive')      ? 'bunch of symbols' :
($type eq 'spanish question') ? 'upside down question mark' :
'plain old period';

IOW - determine sentance type and how to end it.
This is one way of doing the equivalent in if/elsif/else:

if ($type eq 'question') {
     $sentenceEnding = 'question mark';
 }
elsif ($type eq 'demand') {
    $sentenceEnding = 'exclamation point';
 }
elsif ($type eq 'explecitive') {
    $sentenceEnding = 'bunch of symbols';
 }
elsif ($type eq 'spanish question') {
    $sentenceEnding = 'upside down question mark';
 }
else {
   $sentenceEnding = 'plain old period';
 }

IMHO the top code is cleaner, after you get used to it. :-)
Thanks and have a nice day,
Jon


                                    \\\|///
                                    | ~ ~ |
                                   (- o o -)
 ===============================oOOOo=(_)=oOOOo=====
| Jon Lucenius - MultiMedia Director               |
| JCL Technologies                                 |
| E-mail: mailto:jonl@magpage.com                  |
| Office: 302-369-3016                             |
| Home  : 302-369-2989                             |
| Snail :17 Deer Run Drive                         |
|       :Newark DE 19702                   Oooo    |
 ==================================oooO====(  )=====
  "Quality Dynamic Technology."    (  )    ) /
      - Custom Progamming           \ (   (_/
       - Graphic Design              \_)
        - Interface Development

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch