From my script I can do these ok:
my $return = my::module::exit_routine(); sub reverse_modifier { # I modify default behaviour of the exit routine if I get passed - som +e times I am not needed. } my %modifier = ( reverse_modifier => \&reverse_modifier ); my $return = my::module::exit_routine(\%modifier);
In my::module::exit_routine I can deal with %modifier being present or not:
my %revmod = eval { %{ $_[0] } }
But here is my new sticking point - I am unable to find a way to do this from my script:
my $log = LogSimple->new(_exit => my::module::exit_routine(\%modifier) + ); $log->err("An error occured, _exit will happen before I exit but now I + want to force exit_routine to also use the \%modifier as well")
When an error is trapped and $log->err is executed I get: Not a CODE reference at /usr/local/lib/.../LogSimple.pm line 122: From my LogSimple package line 122 = $exit_ref->($self); Effectively I am trying to send a reference which has another reference as one of it's parameters and my syntax is completely jiggered. Infact, the whole concept could be busted up now that I am trying to introduce %modifier to plug up a hole I never knew I had.
Package LogSimple ... sub wlog { my ($self,$MESSAGE,$ERR,$LEVEL,$LOGLEVEL) = @_; my $TIME = datetime(); my $exit_ref; if ( $LOGLEVEL <= $self->{_loglevel} ) { open (LOG, ">>$self->{_log}") || warn "Unable to open log file + $self->{_log}: $!"; print LOG "$LEVEL: $TIME : $self->{_script} : $MESSAGE\n"; print "$LEVEL: $TIME : $self->{_script} : $MESSAGE\n" if ( $se +lf->{_verbosity} > 0 ); close (LOG); } if ( $ERR ) { if ( exists $self->{_exit} ) { use Data::Dumper; print Dumper $self->{_exit}; $exit_ref = $self->{_exit}; $exit_ref->($self); # LINE 122 if ( $LOGLEVEL <= $self->{_loglevel} ) { open (LOG, ">>$self->{_log}") || warn "Unable to open log file + $self->{_log}: $!"; print LOG "$LEVEL: $TIME : $self->{_script} : $MESSAGE\n"; print "$LEVEL: $TIME : $self->{_script} : $MESSAGE\n" if ( $se +lf->{_verbosity} > 0 ); close (LOG); }; } exit $ERR } }
Any assistance much appreciated. Regards, Darren
In reply to Re: Dereferencing %hash that does not exist. by perldarren
in thread Dereferencing %hash that does not exist. by perldarren
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |