When I use the set_die_handler I get duplicate output (it is not STDERR output because I redirect that in the script):

#!/usr/bin/perl -w use strict; use CGI::Carp qw|set_die_handler|; use Foobar; BEGIN { sub extra_special_die_handler { my ($msg) = shift; print qq|Content-Type: text/html\n\n|; print qq|<html><body>|; print qq|<h1>Error</h1>|; print qq|$msg</body></html>|; } set_die_handler(\&extra_special_die_handler); } open( STDERR, '>>', 'testerror.log'); my $foo = Foobar->new(); print $foo->fooish(); print qq|\n\nall okay\n|; close(STDERR);

Foobar.pm in a separate file:

package Foobar; sub new { return bless {}; } sub fooish { my ($self, $somevar) = @_; if ($somevar) { return "Empty nest!"; } else { die "I died here!"; } }

Produces,

Content-Type: text/html <html><body><h1>Error</h1>I died here!</body></html>Content-Type: text +/html <html><body><h1>Error</h1>[Sat Jul 16 19:57:35 2016] testCGI_Carp.pl: +I died here! at Foobar.pm line 12. </body></html>

Any ideas on how I can just get one or the other output?

Celebrate Intellectual Diversity


In reply to Duplicate CGI::Carp Output by InfiniteSilence

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.