leriksen has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that is reporting the following -

Use of unintialized value at (eval 16) line 16.

My script doesn't use eval, but does use a lot of standard modules, and some fairly standard CPAN modules (Log::Log4perl, DBI, Pod::*, Date::Calc).

The eval number changes quite often, but not the line number, so I thnk that means the same line of the same eval'ed code is failing.

How do I track down where the eval is happening?

I have 2500 lines of my own .pm's, so there is a lot of stuff happening.

Ideally I'd like to know the module and either the line or subroutine that is complaining.

Is there anyway to do this short of breaking out the perl debugger?

Replies are listed 'Best First'.
Re: tracing eval
by bart (Canon) on Jan 13, 2003 at 01:28 UTC
    The eval number changes quite often, but not the line number, so I thnk that means the same line of the same eval'ed code is failing.
    Probably, yes.
    How do I track down where the eval is happening?
    You can use one of the routines from Carp which produce a stack trace. Attach either confess() or cluck() to $SIG{__WARN__} — the latter is fatal, the former a warning.
    #!perl -w use Carp; local $SIG{__WARN__} = \&Carp::cluck; sub foo { my($x, $y) = @_; return eval '$x+$y'; } print foo(5); # should get 2 arguments;
    Use of uninitialized value in addition (+) at (eval 1) line 1. eval '$x+$y ;' called at test.pl line 6 main::foo(5) called at test.pl line 8 5

    p.s. For some reason unclear to me, I get no output using \&Carp::confess. Any hints on why are welcomed.

      tiny nit - former, not latter. see perldoc Carp

      cluck - warn of errors with stack backtrace (not exported by default)
      confess - die of errors with stack backtrace

Re: tracing eval
by tall_man (Parson) on Jan 13, 2003 at 01:19 UTC
    I would suggest the module Devel::Trace.

    Use it like this:

    perl -d:Trace qqq.pl
    It will trace the execution line-by-line. This will be verbose, but you can grep the output for where your failure happens.
Re: tracing eval
by rinceWind (Monsignor) on Jan 13, 2003 at 16:45 UTC
Re: tracing eval
by Ryszard (Priest) on Jan 15, 2003 at 07:25 UTC
    I use this technique to ferret out these errors:
    $SIG{__WARN__} = sub { warn @_; $i=0; while(($pack, $file, $line, $subname, $hashargs, $wantary) = caller($i++)){ print STDERR " WARN pack='$pack' file='$file' line='$line' ", "subname='$subname'\n"; } }

    I cant claim authorship of the code, I found it by googling the newsgroups...