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.
|
---|