Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re:{3} Strict, strings and subroutines

by jeroenes (Priest)
on Oct 10, 2001 at 18:44 UTC ( #117998=note: print w/ replies, xml ) Need Help??


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.


Comment on Re:{3} Strict, strings and subroutines
Download Code
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://117998]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-12-25 22:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls