in reply to Re^2: A perl buffer
in thread A perl buffer

... which fails when function($input) returns the empty string, 0 or undef. These values are often used when the most expensive search came up fruitless :).

Replies are listed 'Best First'.
Re^4: A perl buffer
by betterworld (Curate) on Aug 10, 2008 at 16:20 UTC

    I knew that someone would find this loophole ;)

    Well, it would not exactly "fail", it would just ignore the cache. Perl 5.10 has help for us:

    my $result = $cache{$input} //= function($input);

    Of course, there might still be the case where the function returns undef or a list or depends on the context. Before conjuring up a perfect solution that honours all special cases, I'd better let you use Memoize as recommended above :)

      You can use exists. Of course, you still have to know the context you're being called in...