my @nums = qw /3.34 3.67 4.75 4.98/; my $diff = -1; for (my $i = 1; $i < @nums; $i ++) { my $d = abs ($nums [$i] - $nums [$i - 1]); $diff = $d if $diff < $d; } print "Greatest difference is $diff\n" unless $diff < 0;
Note that the above code is untested.
Abigail
In reply to Re: Comparing numbers
by Abigail-II
in thread Comparing numbers
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |