in reply to Function reference undef when extract from hash?

Declare and assign to %Op before trying to call any functions it contains. The subref assignments occur at runtime, so any code that executes before that will find an empty hash.

Replies are listed 'Best First'.
Re^2: Function reference undef when extract from hash?
by Anonymous Monk on Mar 04, 2008 at 05:25 UTC
    So that I need to declare a subroutine prototype if I declare the hash outside of the function?

      No.

      You need to declare the hash before you try to use it.

      This will work:

      # hash declaration # sub declarations # call some sub that uses the hash

      This will not work:

      # call some sub that uses the hash # hash declaration # sub declarations

      If you want to experiment with this on your own, move all of the code into individual subroutines and call them from main():

      # declare this as a file-scoped lexical my %Op; main(); # subs follow sub main { assign_to_Op(); do_something_else(); } sub assign_to_Op { %Op = ( ... ); } sub do_something_else { my $code = $Op{ ... }; $code->(); }