in reply to Find a number in a list closest to a target
You could just loop threw comparing the times. No need for hashes and sorting and keys then.
my $BestTime; my $BestOffBy; my $ctime = (stat($key))[10]; print "IN MULTIPLES \$ctime is $ctime\n"; for (@returns) { print "Working Multiple match: $_\n"; my $temp = abs($ctime - $_); if ($temp < $BestOffBy) { $BestOffBy = $temp; $BestTime = $_ } } print "$BestTime is only $BestOffBy away from $ctime.";
I'm not sure this is any better or faster but eliminating the reverse, sort, and keys of the hash could be important if you are checking alot of times.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Find a number in a list closest to a target
by gnu@perl (Pilgrim) on Jul 25, 2003 at 14:33 UTC | |
by BrowserUk (Patriarch) on Jul 25, 2003 at 15:02 UTC | |
by eric256 (Parson) on Jul 25, 2003 at 19:50 UTC | |
by BrowserUk (Patriarch) on Jul 25, 2003 at 22:51 UTC | |
|
Re: Re: Find a number in a list closest to a target
by gnu@perl (Pilgrim) on Jul 25, 2003 at 14:53 UTC |