in reply to How to call a sub ref from a hash

You want as the last line:
$Procedures{$Procedure}->($Parameter);

Replies are listed 'Best First'.
Re^2: How to call a sub reff from a hash
by NateTut (Deacon) on Dec 15, 2008 at 22:06 UTC
    I think you've goten me on the right track, but this:
    #!/usr/bin/perl use strict; use warnings; sub Procedure_Name_1 { my($Parm) = shift; print($Parm); } my %Procedures; $Procedures{'ProcName1'} = \&Procedure_Name_1; my $Procedure = 'ProcName1'; my $Parameter = 'Some Value'; &$Procedures->{$Procedure}($Parameter);
    still fails...

      Because you have no scalar $Procedures declared (you have a hash %Procedures, but that's something completely different).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Yes, but I'm trying to access an element of that hash.
          A reply falls below the community's threshold of quality. You may see it by logging in.

      Taking your code and then switching the last line like he said makes it work perfectly.

      #!/usr/bin/perl use strict; use warnings; sub Procedure_Name_1 { my($Parm) = shift; print($Parm); } my %Procedures; $Procedures{'ProcName1'} = \&Procedure_Name_1; my $Procedure = 'ProcName1'; my $Parameter = 'Some Value'; $Procedures{$Procedure}->($Parameter);

      I don't understand why you ignored his advice but i would recommend trying it as written in the future.

      BTW you could read the last line as "get the value of $Procedures{$Procedure} and then run it as a coderef ->( passing it $Parameter)"


      ___________
      Eric Hodges