[Chicago-talk] Delete element from array

Andy_Bach at wiwb.uscourts.gov Andy_Bach at wiwb.uscourts.gov
Fri Jul 11 12:54:59 PDT 2008


> ... There's a CPAN module for this, but basically
> it's a matter of avoiding the retest by
> caching the results (in a hash say):
my %bad_symbols;
sub symbol_is_bad {
   my ($test_sym) = @_;
   return 1 if $bad_symbols{$test_sym};
    my $symbol = shift;

    if (foo1) {

Sorry, I missed the shift already in there:
my %bad_symbols;
sub symbol_is_bad {
    my $symbol = shift;
    return 1 if $bad_symbols{$symbol};

    if (foo1) {
          $bad_symbols{$symbol}++;

would be fine.  The module is Memoize  - Make functions faster by trading
space for time
DESCRIPTION
       ‘Memoizing’ a function makes it faster by trading space for time.
It does this by caching the return values of the function in a table.
       If you call the function again with the same
       arguments, "memoize" jumps in and gives you the value out of the
table, instead of letting the function compute the value all over again.

It's quite slick in that it'll handle any sub that has consistent
input->return values as easily as:
    use Memoize;
    memoize('symbol_is_bad');

a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach at wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932

Accordion, n.:        A bagpipe with pleats.


More information about the Chicago-talk mailing list