in reply to How to locate an error in a CGI application

It occurs in the eval at line 9, and in the evaled string it's in line 86.
  • Comment on Re: How to locate an error in a CGI application

Replies are listed 'Best First'.
Re^2: How to locate an error in a CGI application
by almut (Canon) on Aug 16, 2007 at 12:23 UTC

    It's the 9th execution of an eval (not an eval on line 9). For example, the script below would give

    Use of uninitialized value in array element at (eval 9) line 4.
    #!/usr/bin/perl use warnings; my $code_err = q| my @arr; my $i; $arr[$i] = 0; # line 4 within this code snippet |; my $code_ok = q|my $var = ""|; eval $code_ok for (1..8); eval $code_err; # 9th eval, but line 14 in this script

    Unfortunately, I don't think there's an easy, straightforward way to locate the warning based on the info you've got...

      Thanks for the clarification. Unfortunately I tested it with one eval at line one - not a good idea, of course ;-)

      A possible way to find the error woud be to Carp::confess() on errors, I think that works via a SIG{__DIE__} handler, but I don't know that offhand.

      Update: I just tested it, it doesn't seem to work inside an eval.

      Thanks, at least now I know what to debug in my code.
        Mind you, I'm rather clueless, so take what I say with a ton of salt:

        Try adding a "use Carp;" and an INIT block like "INIT { $SIG{__WARN__ }=sub { carp "Caught it"; } };"

        #!/usr/bin/perl use warnings; use Carp; INIT { $SIG{__WARN__}=sub {carp "gotcha!";}; }; my $code_err = q| my @arr; my $i; $arr[$i] = 0; # line 4 within this code snippet |; my $code_ok = q|my $var = ""|; eval $code_ok for (1..8); eval $code_err; # 9th eval, but line 14 in this script E:\><code> gets me <code>E:\>perl example.pl gotcha! at example.pl line 6 main::__ANON__('Use of uninitialized value in array element at + (eval 9) line 4.\x{a}') calle d at (eval 9) line 4 eval ' my @arr; my $i; $arr[$i] = 0; # line 4 within this code snippet ;' called at example.pl line 17 E:\>type example.pl
        clueless
Re^2: How to locate an error in a CGI application
by rbi (Monk) on Aug 16, 2007 at 12:11 UTC
    I have no eval at line 9 of the mainscript.cgi (empty line, and still line 9 is indicated if I put some warn messages above line 9 just to increment the lines at the top of the mainscript.cgi code).
    Could it be in one of the modules I'm using ? How can I locate it, in that case ?