[tpm] Is there a three-way version of...

Uri Guttman uri at StemSystems.com
Fri May 29 12:32:22 PDT 2009


>>>>> "MK" == Madison Kelly <linux at alteeve.com> writes:

  MK> Dave Doyle wrote:
  >> Addendum:
  >> 
  >> You can chain the ternary operator as much as you want.  Laying out in
  >> a table-like way is adviced.
  >> 
  >> my $title = $condition1 ? 'result1'
  >> : $condition2 ? 'result2'
  >> : $condition 3 ? 'result3'
  >> # ... more lines here
  >> :                      'default';
  >> 
  >> --
  >> dave.s.doyle at gmail.com

  MK> Huh, didn't realize you could chain it like that. Thanks!

just to add to that, you can chain ANY expression in perl (as with most
any language). chaining is how you build up complex expressions. this is
no different that doing $x * $y + $z which is chaining too. thinking you
can't chain ?: is like newbies who see print <<EOT and thing << is part
of the print function instead of being another way to quote strings.

the key thing to learn when chaining is precedence and if you don't know
it, use parens.

uri

-- 
Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


More information about the toronto-pm mailing list