in reply to Re^3: Calling a hash member
in thread Calling a hash member
my $r = \{expr};
is the same thing as
my @rv = expr; my %h = @rv; my $hr = \%h; my $r = \$hr;
There's no coderef anywhere in there. That sets the value at key firstTask to a reference to a reference to a hash which was initialized with the result of prepare.
Furthermore,
$ThingsToDo{firstTask};
is a no-op. Even if $ThingsToDo{firstTask} returned a code reference, there's nothing to cause the referenced code to get executed. To execute the code referenced by $ThingsToDo{firstTask}, use
&{$ThingsToDo{firstTask}}();
or better yet,
$ThingsToDo{firstTask}->();
Finally, $project needs to be variable. It needs to be an argument.
I think you meant
my %ThingsToDo = ( firstTask => sub { my $pkg = shift; $pkg->prepare(@_) }, ); ... $ThingsToDo{firstTask}->($project);
But that's much more complex than required, and would involve lots of redundancy (sub { my $pkg = shift; $pkg->XXX(@_) }.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Calling a hash member
by geekphilosopher (Friar) on Dec 14, 2006 at 02:42 UTC | |
by ikegami (Patriarch) on Dec 14, 2006 at 03:58 UTC |