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

Tegels, Kent Kent.Tegels at hdrinc.com
Thu Jan 20 09:30:42 PST 2005


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 at pm.org [mailto:omaha-pm-bounces at pm.org] On Behalf
Of Jay Hannah
Sent: Thursday, January 20, 2005 10:57 AM
To: omaha-pm at 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 at pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm


More information about the Omaha-pm mailing list