I'm really at a loss why I am getting a 500 error when I attempt to execute the following script via a Web browser and the following error in my error log:
[Mon Nov 27 13:49:00 2006] [error] [client 64.233.172.2] Premature end
+ of script headers: /home/www/cgi-bin/testing.pl
The script WORKS fine on a server that has
HTTP::Request::Common, but the error occurs on a machine where this module is not available.
I added the
eval assuming that it would effectively test if this module was available, and, if not, the error would be displayed on the Web browser (or I could suppress it entirely), and then I can continue doing other things without using the module.
Here is the script...
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "here we go again...";
eval {
require LWP::UserAgent;
use HTTP::Request::Common;
my $ua = LWP::UserAgent->new;
my %post;
my $content = $ua->request(POST "http://www.cnn.com", [%post])
+->as_string;
print $content;
};
if (@$) {
print "ERROR: @$";
}
print "more stuff would happen here";
My questions are: 1) why doesn't the use of
eval successfully suppress the premature EOS error? 2) is there a better way to test if the module is available, and, if not, then don't use it, and do other things? Basically this script will execute on a few servers and I want to test if the modules are available, and, if so, then use them and do some things, BUT if they aren't, then don't use them and do some other things... WITHOUT causing 500 errors... help?
Thanks!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.