2012/07/24

memoize caveat

Functions that return references to values
that may be modified by their callers must not be memoized.

use Memoize;

sub iota {
    my $n = shift;
    return [1 .. $n];
}

memoize 'iota';

$i10 = iota(10);
$j10 = iota(10);

pop @$i10;

print @$j10;

No comments:

Post a Comment