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

RE: [Omaha.pm] if ($a > $b) { $b = $a }



Well, there's the dreaded:
$b = ($a > b$ ? $a : $b); 

But that's less readable than what you have. 

Optionally, you could roll your own max sub if you like.

Helpful?
kt

-----Original Message-----
From: omaha-pm-bounces@pm.org [mailto:omaha-pm-bounces@pm.org] On Behalf
Of Jay Hannah
Sent: Thursday, January 20, 2005 10:57 AM
To: omaha-pm@pm.org
Subject: [Omaha.pm] if ($a > $b) { $b = $a }


I seem to write this pattern in my code a lot when I'm trying to find
the maximum value of something:

if ($a > $b) {
   $b = $a;
}

Is there some slick Perl operator that does that cleaner?

That pattern gets pretty ugly in my real code. e.g.:

if ($running_simul{$type} > $stats{$type}{'max simul'}{$time}) {
    $stats{$type}{'max simul'}{$time} = $running_simul{$type}; }

j


_______________________________________________
Omaha-pm mailing list
Omaha-pm@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm