I do think you're onto something. It looks to me like it might be something worth reporting to Lincholn Stein (CGI::Carp's author)... or to the p5p people, since CGI::Carp is a core module. Not sure which is more appropriate.

Here are a few tests that I found interesting, and which give results that are in some ways inconsistant with documentation.

use strict; use warnings; use CGI::Carp; eval { die "Ouch. 1" }; print $@, "\n" if $@; eval { die "Ouch. 2\n" }; print $@, "\n" if $@; eval { CORE::die "Ouch. 3" }; print $@, "\n" if $@; eval { CORE::die "Ouch 4.\n" }; print $@, "\n" if $@; __Output__ Ouch. 1 at C:/Perl/lib/CGI/Carp.pm line 312. Ouch. 2 Ouch. 3 at C:\Perl\scripts\mytest.pl line 14. Ouch. 4

And now the same tests but with Carp.pm (not CGI::Carp)...

use strict; use warnings; use Carp; eval { die "Ouch. 1" }; print $@, "\n" if $@; eval { die "Ouch. 2\n" }; print $@, "\n" if $@; eval { CORE::die "Ouch. 3" }; print $@, "\n" if $@; eval { CORE::die "Ouch 4.\n" }; print $@, "\n" if $@; __OUTPUT__ Ouch. 1 at C:\Perl\scripts\mytest.pl line 8. Ouch. 2 Ouch. 3 at C:\Perl\scripts\mytest.pl line 14. Ouch. 4

Clearly Carp.pm's output is what we want. And CGI::Carp's output is improper. This bug appears only in scripts that are evaled. mod_perl scripts are eval'ed too, so the problem shows up there too. The POD for CGI::Carp says that CGI::Carp is a CGI-friendly equivilant to Carp. But it turns out that CGI::Carp is not as good as Carp at reporting the correct line numbers. I would consider this a bug.

As for why a "\n" character in the die string suppresses the printing of line numbers, that's a mystery for which I can't find any documentation anywhere.


Dave


In reply to Re: CGI::Carp peculiarity by davido
in thread CGI::Carp reports line numbers incorrectly by esharris

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.