in reply to Re^2: Function reference undef when extract from hash?
in thread Function reference undef when extract from hash?
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->(); }
|
|---|