in reply to Re: '100 elsif's vs hash of coderef's
in thread '100 elsif's vs hash of coderef's
I think I would put the dispatched functions in a separate namespace:
It's no longer necessary to munge the function names, and the functions are easily factored out to a separate module (which could, of course, also be done with the original approach).c:\@Work\Perl>perl -wMstrict -le "my @args = qw(hi there); ;; for my $do_this (qw(Title Description Object Fooble Properties)) { my $code = Dispatcher->can($do_this); ;; if (!$code) { print qq{Missing Handler for '$do_this'}; next; } ;; $code->(@args); } ;; { package Dispatcher; ;; sub Title { print qq{title handler: @_}; } sub Description { print qq{description handler: @_}; } sub Object { print qq{object handler: @_}; } sub Properties { print qq{properties handler: @_}; } } " title handler: hi there description handler: hi there object handler: hi there Missing Handler for 'Fooble' properties handler: hi there
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: '100 elsif's vs hash of coderef's
by GrandFather (Saint) on Dec 10, 2015 at 23:52 UTC | |
by AnomalousMonk (Archbishop) on Dec 11, 2015 at 08:35 UTC |