http://www.perlmonks.org?node_id=117998


in reply to Re: Re (tilly) 1: Strict, strings and subroutines
in thread Strict, strings and subroutines

Great.

A pity you don't cache the possibility that it doesn't exist:

BEGIN { my %cache; sub do_it { my $func = shift; $cache{$func} = do { local @ISA; __PACKAGE__->can("do_$fun") } unless exist $cache{$func}; $cache{$func}->(@_); } }
Jeroen

Update: merlyn is right. Fixed that.

Replies are listed 'Best First'.
Re: Re:{3} Strict, strings and subroutines
by merlyn (Sage) on Oct 10, 2001 at 19:45 UTC
    BEGIN { my %cache; sub do_it { my $func = shift; $cache{$func} = do { local @ISA; __PACKAGE__->can("do_$fun") } unless defined $cache{$func}; $cache{$func}->(@_); } }
    This does precisely what mine does. Did you mean "exists" there instead of "defined"?

    -- Randal L. Schwartz, Perl hacker