On Thu, Dec 09, 2004 at 07:16:02AM -0700, Kirk Bauer wrote:

> Not a beginner's question, but I don't know what other mailing list to
> use.  Please direct me accordingly.

Not exactly mailing lists, but comp.lang.perl.moderated and
perlmonks.org might be helpful.  (Actually, you can access
comp.lang.perl.moderated by mail.)

> I have a Perl program that defines numerous functions by eval'ing a
> string (read from an external file).  I have a comprehensive
> $SIG{__WARN__} handler but for errors in these functions all I get is
> '(eval \d+)' for the file name containing the error.
> 
> So, here is my first question -- in my $SIG{__WARN__} handler, if I get
> a warning from a (eval \d+) file, can I figure the name of the function
> that was being executed when the warning was triggered?
> 
> But I have a better solution I'm hoping for.  The number inside of the
> (eval \d+) description seemed to increment once per eval, and by looking
> at the Perl source code sure enough it seems to be tracked by the
> PL_evalseq variable.
> 
> If I can find out what number was assigned to my eval statement, I could
> remember this and relate later warnings as appropriate.  Something like
> this:
> 
> my $str = "sub Blah {...}";
> my @eval_ids;
> eval $str;
> my $id = ????????
> $eval_ids[$id] = $str;
> 
> $SIG{__WARN__} = sub {
>    if ($_[0] =~ /\(eval (\d+)\)/) {
>       print "Error was in code: $eval_ids[$1]\n";
>    }
> };
> 
> Any help with this, pointers to other mailing lists, or alternative
> approaches would be greatly appreciated.
> 
> FYI the strings being eval'd come from external files that are split
> into section and are eval'd in several pieces.

This all sounds like a lot of work.  If the code you want to eval is in
a file somewhere you likely know or can find out the name of the file
and the line number from where it came.  I suggest adding

  #line linenumber file

at the beginning of the code you want to eval.

  $ perl -we 'eval "#line 4 qaz\n\$x = \$y + 1"'
  Use of uninitialized value in addition (+) at qaz line 4.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to