(You can add error checks, etc.)sub dispatch { my $self = shift; my $meth = { a=>"first", b=>"second" }->{shift(@_)}; $self->$meth(); }
BTW if you can, it makes more sense to drop your dispatch all together and let client code look for the methods by name. And then you can put error checks in an AUTOLOAD.
In reply to Re (tilly) 1: Dispatching Method Objects
by tilly
in thread Dispatching Method Objects
by ehdonhon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |