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

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

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!