in reply to Re^2: eval question
in thread eval question

I've used dispatch tables in C, even though it has a switch statement. The advantage of dispatch tables is that you don't have to repeat the code the lists the args and you don't have to repeat the code that stores the return value.
my @callbacks = ( &some_handler, &another_handler, &foo_handler, &bar_handler, ); my $rv = $callbacks[$event]->($arg0, $arg1);

vs

my $rv; given ($event) { when SOME_EVENT { $rv = some_handler ($arg0, $arg1); } when ANOTHER_EVENT { $rv = another_handler($arg0, $arg1); } when FOO_EVENT { $rv = foo_handler ($arg0, $arg1); } when BAR_EVENT { $rv = bar_handler ($arg0, $arg1); } };

Arrays of function procs are also useful when the entire list needs to be executed.

foreach (@procs) { $_->(); }