August 1999 | Perl Hardware Store | Slide #34 |
{ my %cache;
sub compare_dates { ($cache{$a} ||= to_number($a)) <=> ($cache{$b} ||= to_number($b)) } }
Best of both worlds:
If numeric version is in cache, we get it instantly
Otherwise, we compute and install it
Exactly 1,000 calls to to_number
Joseph Hall calls this the Orcish Maneuver because its notable features are
The ||
and the cache
Next | Copyright © 1998 M-J. Dominus |