in reply to Calling a hash member
I'm not sure if this applies here.. But I got a funny feeling.
If you are doing object oriented, then..#!/usr/bin/perl -w use strict; my $o = new Wonderful; print $o->whichmethod('one'); print $o->whichmethod('two'); exit; package Wonderful; sub new { my $class = shift; my $self= {}; bless $self, $class; return $self; } sub whichmethod { my $self = shift; my $which_method = shift; my $method = { # this will not work!: one => \&method1 one => sub { $self->method1 }, two => sub { $self->method2 }, }; return &{$method->{$which_method}}; } sub method1 { my $self= shift; return 1 } sub method2 { my $self = shift; return 2; } 1;
|
---|