Question : Using LWP in Perl script getting Internal Server Error

I am trying to run a Perl program on my Apache Server. The code:

#!/usr/usc/bin/perl -w

use LWP::Simple;
use strict;
my $content = get("http://www.google.com");
die "Couldn't get it!" unless defined $content;

I think, it is fine, but it gives me an Internal Server Error. I checked the Error Logs it showed this:
"Premature end of script headers: "

Kindly let me know, how to trace it and what can be a possible solution, I have tried to check everything, from path , to access rights, but does not seem to work. It works fine, if I run a simple  printout, but the moment I start using LWP, it crashes down giving Internal Server Error

Answer : Using LWP in Perl script getting Internal Server Error

running from a browser? You need to print an http header before trying to print anything back to the browser:

#!/usr/usc/bin/perl -w

use LWP::Simple;
use strict;
print "Content-type: text/html\n\n";
my $content = get("http://www.google.com");
die "Couldn't get it!" unless defined $content;
print $content;
Random Solutions  
 
programming4us programming4us