in reply to How can I change the perl program involving if-elsif-else conditional to get correct result?

Some fun with conditional operator (perlop).
#!/usr/bin/perl -w use strict; my $xa=0.9; my $xb=0.7; my $xc=0.5; my @triplet = ($xa,$xb,$xc); my $m = ( ($xa>$xb and $xa>$xc)? 0: ($xb>$xc? 1: 2) ); print "$triplet[$m] is largest\nvalues are ", sprintf("%.2f, %.2f", $triplet[($m+1)%3]/$triplet[$m], $triplet[($m+2)%3]/$triplet[$m]);
Update: typo in code
Update2: better perf
my $m = ( $xa>$xb? ($xa>$xc?0:2): ($xb>$xc?1:2) );
  • Comment on Re: How can I change the perl program involving if-elsif-else conditional to get correct result?
  • Select or Download Code