August 1999 | Perl Hardware Store | Slide #32 |
Another solution: Memoize date-to-number conversion function:
use Memoize;
sub compare_dates { to_number($a) <=> to_number($b); }
# Convert "Apr 2, 1969" to "196990402" sub to_number { my ($m, $d, $y) = ($_[0] =~ /(\w{3}) (\d+), (\d+)/);
sprintf("%04d%02d%02d", $y, $m2n{$m}, $d); }
memoize 'to_number';
Only 1,000 splits now, a big improvement
Next | Copyright © 1998 M-J. Dominus |