• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

CGI/PERL LWP::Simple..

jskam

New Member
I have this perl script as follows
Code:
#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);
use LWP::Simple;
use CGI;

$query = new CGI;

print $query->header;

$content = get("http://www.cpan.org/doc/FAQs/index.html");

open FILEHANDLE, ">file.txt";
print FILEHANDLE $content;
close FILEHANDLE;


When i run this script, it runs successfully, the file.txt is also created but nothing is written to the file.txt, its empty...

Any beginners or pros or masters or experts on perl, who can help me out here??..thanks in advance :)
 
check the contents of $content variable when you are calling get() on it, check whether anything is returned or not, it may be problem that get() is not successfull or due to restrictions cannot grab the contents of web page
 
nag said:
check the contents of $content variable when you are calling get() on it, check whether anything is returned or not, it may be problem that get() is not successfull or due to restrictions cannot grab the contents of web page

How do i check the contents of $content variable???
 
hey i tried
Code:
print $content;
But It doesnt print anything...empty...
which means that there might be some error, while getting the file using the get method
Code:
$content = get("http://www.cpan.org/doc/FAQs/index.html");

what you say??what can be the possible solution?
 
the variable is empty because, may be you are behind a firewall or some likely problem, try using some other method to grab the contents of web page.:) I think most probably you would be unable to create a socket for outgoing connection ... try your script on some other host that allows direct outgoing connection to internet.
 
may be..i shall try it on other servers and i will know...how it is...or may be i might try and reprogram it in such a way that i works, on the current server...

i will let you know, what it is....

thanks, anyways, for helping out until here..
 
jskam said:
I have this perl script as follows
Code:
use LWP::Simple;


What host are you using ?
You have to note that Netfirms and some other fxxxing hosts don't have the LWP module support.
 
NickNet said:
What host are you using ?
You have to note that Netfirms and some other fxxxing hosts don't have the LWP module support.
Well the host i am with, does support LWP::Simple.
 
The following works perfectly for me.

Code:
#!/usr/bin/perl
use LWP::Simple;

print "Content-Type: text/html\n\n\n";

my $content = get("http://www.cpan.org/doc/FAQs/index.html");
print $content;

open (OUT,">output.text");
print OUT $content;
close OUT;

__END__
 
Back
Top