in reply to Re: Tying events to perl warnings and errors
in thread Tying events to perl warnings and errors

The only problem with the $SIG{__WARN__} method is that I don't get the data I want. I'm not a perlguts guy, so maybe someone can point the way for what I mentioned I wanted in the article, which is access to the variable list for the subroutine.

What I want to do is upon receipt of the error, dump the variable state for the subroutine out to disk. Timestamping is all well and fine, but it doesn't get me the information that I'm really needing. Any ideas?

--Chris

e-mail jcwren
  • Comment on (jcwren) Re: (2) Tying events to perl warnings and errors

Replies are listed 'Best First'.
RE: (jcwren) Re: (2) Tying events to perl warnings and errors
by reptile (Monk) on Sep 14, 2000 at 00:23 UTC

    Localize the handler with a closure, like this:

    sub foo { my ($a, $b, $c) = @_; my %hash = (a => {b => {c => 0}}); # whatever other variables you want to initialize local $SIG{__WARN__} = sub { # dump those variables here }; print $hash{$a}->{$b}->{$c}; # ... }

    The variables you want to dump will be in scope of the __WARN__ handler and you can do whatever you like with them.

    local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }