perlquestion
InfiniteSilence
<p>
When I use the <code>set_die_handler</code> I get duplicate output (it is not STDERR output because I redirect that in the script):
<code>
#!/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);
</code>
<p>Foobar.pm in a separate file:</p>
<code>
package Foobar;
sub new {
return bless {};
}
sub fooish {
my ($self, $somevar) = @_;
if ($somevar) {
return "Empty nest!"; }
else {
die "I died here!";
}
}
</code>
<p>Produces,<p>
<code>
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>
</code>
<p>Any ideas on how I can just get one or the other output?</p>
</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-45622">
<P><I>Celebrate Intellectual Diversity</I>
</div></div>