--- Jeff Pinyan <[EMAIL PROTECTED]> wrote:
> On May 22, Paul said:
> 
> >I know that in many C compilers, the a ? b : c construct with the
> >ternary ?: operator si not stable after the second or third nesting,
> >but I've never seen that sort of problem in tests I've run in Perl.
> 
> The only to watch out for is precendence:
> 
>   $a ? $b = $c : $b = $d;
> 
> is like
> 
>   ($a ? $b = $c : $b) = $d;
> 
> which always sets $b to $d.

Yup, tho in that case I'd usually say

   $b = $a ? $c : $d;

> 
> > sub rate ($) {
> >    $_[0] eq 'A' ? .03 :
> >    $_[0] eq 'B' ? .05 :
> >    $_[0] eq 'C' ? .06 :  
> >                   .08;   # the default
> > }
> 
> That's fine, but I prefer to use hashes for that sort of thing.
> 
>   {
>     my %rates = qw(
>       A .03
>       B .05
>       C .06
>     );
>     sub rate {
>       exists $rates{$_[0]} ? $rates{$_[0]} : .08
>     }
>   }

Yep! But the actual function has a little more processing:

 sub charge ($) { # receives a boolean; rerate or not
   my $band = @_ and $routes{$mf03->route} ? 0 : $mf03->band;
   my $mou = $mf03->bmou*($peak{$mf03->tod}||.50) #50% off-peak
discount
      if $band; # wasted effort on 'X', but that's rare
   return int(100 * sprintf "%.2f",
      $band eq '0' ? .12 :
      $band eq 'X' ? .12 :
      $band eq 'A' ? .04 + $mou * .03 :  # setup is .04 per call
      $band eq 'B' ? .04 + $mou * .05 :
      $band eq 'C' ? .04 + $mou * .06 :
                     .04 + $mou * .08);
 }

Still tossing this salad, 
but I think I've got all my veggies in it now. =o)


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to