in reply to Re^5: How to call a sub reff from a hash
in thread How to call a sub ref from a hash

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^7: How to call a sub reff from a hash
by ikegami (Patriarch) on Dec 16, 2008 at 01:52 UTC

    $Parameter is not a hash element it is an argument to the procedure reference stored in the hash.

    I know. I didn't use ->{}. I used ->() which calls the referenced sub.

    I'm sorry but that doesn't work either

    Yes it does.

    #!/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);
    >perl 730516.pl Some Value
      I apologize you are right of course, I must have copied wrong before. The real problem here is that I'm not understanding the syntax. Thanks for all the help.

        I'm not understanding the syntax

        ThisCan be written more clearly as
        ${$aref}[$i]$aref->[$i]
        ${$href}{$k}$href->{$k}
        &{$cref}($arg)$cref->($arg)

        In this case, the code ref is stored in a hash, so $cref is a hash lookup.

        my $cref = $hash{$k}; $cref->($arg) | v ( $hash{$k} )->($arg); | v $hash{$k}->($arg);
Re^7: How to call a sub reff from a hash
by duckyd (Hermit) on Dec 15, 2008 at 22:36 UTC
    You want:
    &{$Procedures{$Procedure}}($Parameter);
    or
    $Procedures{$Procedure}->($Parameter);