package Foo; sub new { my($pkg, %args) = @_; my $self = { method => 'correlation', %args }; $self->{funcs}{correlation} = \&$self->correlation; return bless $self, $pkg; } sub correlation { print "This is the correlation function!"; } #### my $x = new Foo(method => 'biscuit'); #### if exists $self->{funcs}{$self->{method}} { $self->{funcs}{$self->{method}}(params); } else { die "Sorry, the method $self->{method} isn't valid!"; } #### #This says "Not a CODE referece at Foo.pm line..." $self->{funcs}{correlation} = \&$self->correlation; #This says "Can't call method 'correlation' on unblessed # reference at Foo.pm line..." $self->{funcs}{correlation} = \&{$self->correlation}; #And this says "Scalar found where operator expected at # Foo.pm line... $self->{funcs}{correlation} = \&($self->correlation);