in reply to Dispatching Method Objects

Well, that is because in your object you now have a package, and what once worked in your main code, is now bundled away in FOO::...

I would suggest something along the following..

package FOO; sub first { print "This is first\n"; } sub second { print "This is second\n"; } sub dispatch { my $self = shift; no strict 'refs'; my $command = shift; print "In dispatch, command = $command\n"; &{$self->{dispatch}{$command}}(); } sub new { my $class = shift; my $self = {}; bless $self, $class; $self->{dispatch} = { 'a'=> $self->can('first'), 'b'=> $self->can('s +econd') }; return $self; } package ::; my $foo = new FOO(); $foo->dispatch('a'); $foo->dispatch('b');
I took references to the methods using can (since I cannot think off the top of my head how to do it otherwise...). It is MUCH better to use code refs than do symbol table lookups on strings... but to do a successful symbol table lookup you would do
$self->$command();
I also move the definition of your dispatch table into the new method, since you should only have to generate this once....

                - Ant
                - Some of my best work - Fish Dinner