( I can't take all credit for this, I first saw it demonstrated by someone on perlmonks, but I don't recall where or what the name was )
Consider:
Consider:
Versus%dispatch = ( foo => \&foo, bar => \&bar, baz => \&baz, qux => \&qux, ); sub foo {} sub bar {} sub baz {} sub qux {} if( exists $dispatch{ $method } ) { $dispatch{$method}->(); }
package dispatch; sub foo {} sub bar {} sub baz {} sub qux {} package main; if( my $ref = dispatch->can($method) ) { $ref->(); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Automating dispatch tables
by liz (Monsignor) on Apr 16, 2004 at 07:45 UTC | |
by BUU (Prior) on Apr 16, 2004 at 07:53 UTC | |
Re: Automating dispatch tables
by davido (Cardinal) on Apr 16, 2004 at 07:58 UTC | |
by BUU (Prior) on Apr 16, 2004 at 08:02 UTC | |
by dragonchild (Archbishop) on Apr 16, 2004 at 11:52 UTC | |
Re: Automating dispatch tables
by demerphq (Chancellor) on Apr 16, 2004 at 14:19 UTC | |
Re: Automating dispatch tables
by kappa (Chaplain) on Apr 16, 2004 at 07:22 UTC | |
Re: Automating dispatch tables
by blakem (Monsignor) on Apr 16, 2004 at 09:49 UTC | |
Re: Automating dispatch tables
by jryan (Vicar) on Apr 16, 2004 at 23:24 UTC | |
Re: Automating dispatch tables
by QwertyD (Pilgrim) on Apr 19, 2004 at 04:36 UTC |
Back to
Meditations