http://qs321.pair.com?node_id=1167895

InfiniteSilence has asked for the wisdom of the Perl Monks concerning the following question:

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