in reply to Re: extracting corresponding values from another array
in thread extracting corresponding values from another array
the code below perfectly calculates the greatest difference between two numbers, but i can't get it to return only the two numbers between whcih the difference lies. Any ideas how I could do this? thanks again. e.g. outputmy $numbers = ('0.12', '0.35','1.34');
the diff between 0.35 and 1.34 is 0.99.
for ($i = 2; $i < @numbers; $i++) { if (defined ($numbers[$i]) && defined ($numbers [$i-1])) { $d = abs ($numbers [$i] - $numbers [$i-1]); $d =~ s/-//g; $diff = $d if $diff < $d; @diff_val = "$numbers[$i]\t$numbers[$i-1]\n"; @diff_val = split ('', $testing); push (@d, $d, $diff_val[0], $diff_val[1]); } } print "Greatest difference in the first sample is $diff\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: extracting corresponding values from another array
by Abigail-II (Bishop) on Dec 03, 2002 at 17:05 UTC |