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

Uri Guttman uri at StemSystems.com
Sat May 30 11:09:50 PDT 2009


>>>>> "JBL" == J Bobby Lopez <jbl at jbldata.com> writes:

  JBL> It basically looks like we're talking about switch statements. An
  JBL> alternate method of doing the same thing would be as follows,
  JBL> though I'm not sure how expensive it is:

  JBL> $a = "";
  JBL> $a = $b if $a = "";
  JBL> $a = $c if $a = "";
  JBL> $a = $d if $a = "";
  JBL> ...
  JBL> $a = "default" if $a = "";

regardless of expense, it helps to have it correct. if you were to check
for numbers then use ==. but for strings use 'eq'. what you have will
assign '' to $a and then fail the if each time and never assign anything
else to $a.

and the chain of if's like that is expensive compared to a chained set
of ?: as yours has to test each time whereas the other will break out
when it has to.

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