There is a nice way to work out where the errors and warnings in eval code are coming from.

If you take a look in perlsyn#Plain-old-comments-(Not!), you'll see a feature that allows you to reset Perls idea of the current file and current line.

If you can use this to embed such a comment into each piece of evalable code, you can have perl tell you both the piece of code and the line number within it that at which the warning or error was encountered.

A crude demo...

P:\test>type test.pl8 #! perl -slw use strict; my $code = q[ #line 4000 "evalcode.pl" print "hello"; print undef; ]; eval $code; P:\test>test hello Use of uninitialized value in print at evalcode.pl line 4001.

By carefully choosing the names you give to your eval blocks (perhaps including the source file name/line number) you should be able to easily translate between the resultant error message and your code.

It would be really nice if it was possible to retroactively add this to eval'd code in CORE and CPAN modules. It sure would save a lot of searching when the messages arise from outside of your own code. Perhaps some sort of recommendation for a standardised filename/eval block/line number to module/source line mapping could be devised?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: warnings within eval{} by BrowserUk
in thread warnings within eval{} by shemp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.