in reply to Re: Dereferencing %hash that does not exist.
in thread Dereferencing %hash that does not exist.
The Dumper output from line 120 should make it clear what $exit_ref will be set to but the error message makes it clear that it is not a code reference. My guess is that my::module::exit_routine(\%modifier) doesn't return a code reference, though it is only a guess as much of your code is not presented.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Dereferencing %hash that does not exist.
by perldarren (Novice) on Sep 04, 2013 at 21:51 UTC | |
If I remove %modifier and send exit => \&Hitachi::Raidcom::exit_routine there's a whole bunch of $VARS but if I try to add the argument as in this snippet, it breaks. Here is the reverse modifier sub and the dispatch table: This is the entire LogSimple module:
| [reply] [d/l] [select] |
by ig (Vicar) on Sep 04, 2013 at 22:55 UTC | |
OK, so Dumper output $VAR1 = \''; shows that $self->{_exit} is not a code ref, as expected. You haven't shown the code of Hitachi::Raidcom::exit_routine, but with the error message and Dumper output, it is reasonably clear what is happening. Your code samples seem to be alternating between exit => \&Hitachi::Raidcom::exit_routine(\%modifier) and _exit => my::module::exit_routine(\%modifier), among other alternatives. Hitachi::Raidcom::exit_routine(\%modifier) executes the subroutine and yields the value it returns. &Hitachi::Raidcom::exit_routine(\%modifier) does the same. The & is optional in this case (with the arguments in parentheses) and makes no difference. \&Hitachi::Raidcom::exit_routine(\%modifier) also runs the subroutine and yields a reference to the value it returns. That's why dumper gives you \''. The \ indicates a reference. In this case, a reference to the empty string. What will probably work for you is (as AnomalousMonk suggested):
With this initialization, $self->{_exit} should be set to a code reference: to the anonymous sub which does nothing but call Hitachi::Raidcom::exit_routine with the argument \%modifier and return whatever that sub returns. The sub isn't executed immediately. It is executed later, in sub wlog, when the code reference is de-referenced and called. But, I haven't tested... While this will probably work for you, I will mention closure (just one of many articles on the subject). It is a confusing feature for many, so I suggest you not worry about it immediately, but once you have this working, learn about closure before making too much use of anonymous subroutines accessing lexical variables. | [reply] [d/l] [select] |
by perldarren (Novice) on Sep 05, 2013 at 10:42 UTC | |
| [reply] |