Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: performance - loops and complex decisions, sub refs, symbol tables, inner and outer if/elses

by Fletch (Bishop)
on Dec 17, 2002 at 15:30 UTC ( [id://220543]=note: print w/replies, xml ) Need Help??


in reply to performance - loops, sub refs, symbol tables, and if/elses

Don't fiddle with the symbol table when just a simple hash of code refs will do.

sub noop { 1; } my %funcs = ( apple => [\&apple_wash, \&apple_core, \&apple_pulp,], bananas => [\&banana_bend, \&banana_hang, \&noop,], ); ## . . . for my $i ( @items ) { unless( exists $funcs{ $type } ) { warn "Bad type `$type'\n"; next; } $_->( $item ) foreach( @{ $funcs{ $type } } ); }

Of course it might make more sense to just make your items proper objects rather than using a dispatch table.

  • Comment on Re: performance - loops and complex decisions, sub refs, symbol tables, inner and outer if/elses
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found