in reply to Re: Subroutines in Dispatch Tables
in thread Subroutines in Dispatch Tables
In your approach, all dispatches have to be integer based (array) where as with a hash, you have the luxury of using any scalar value.
The last bit should be "any string", not "any scalar value".
And in his approach, all dispatches have to be regex-based, and that's rather more luxurious than any constant string.
The cost is in speed. His dispatch takes O(N) to find the correct dispatch, not O(1).
my $action; for my $dispatch (@$dispatch_tables) { my $regex = $dispatch->{regex}; if ($input =~ $regex) { $action = $dispatch->{action}; last; } } die("No match\n") if !$action; $action->($input);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Subroutines in Dispatch Tables
by Limbic~Region (Chancellor) on Sep 23, 2009 at 00:16 UTC |