|
Posted by Gunnar Hjalmarsson on March 2, 2008, 5:17 am
Please log in for more thread options Bennett Haselton wrote:
> I wrote the following script to test whether, if I try writing to an
> invalid filehandle, the error message would get sent to the browser:
>
> #!/usr/bin/perl
>
> use strict;
> use IO::File;
> use CGI::Carp qw(fatalsToBrowser);
>
> print "Content-type: text/html\n\n";
>
> # This will not open a valid filehandle since the script runs as
> nobody
> my $fh = IO::File->new("> doesnotexist.txt");
> print $fh "foo";
>
> die "Die here, if you get this far";
>
> The line 'print $fh "foo";' does generate an error, however that error
> gets written to /var/log/httpd/error_log where it says "Can't use an
> undefined value as a symbol reference at /var/www/html/carptest/open-
> wrong-file-with-carp-fatalstobrowser.cgi line 11". I want that sent
> to the *browser*, not written to the log file. The line 'die "Die
> here, if you get this far";' never gets executed.
As Xho indicated, you may be using a buggy version of CGI::Carp, so it
could be worth trying to upgrade. The usual check of the return value,
when doing IO operations, may be another solution:
my $fh = IO::File->new("> doesnotexist.txt")
or die "Filehandle creation failed: $!";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
|