LWP::Simple get() problem

  • Thread starter Hon Guin Lee - Web Producer - SMI Marketing
  • Start date
H

Hon Guin Lee - Web Producer - SMI Marketing

Hi,

I am having problems with the following code, in which the get() function from the LWP::Simple is not
retrieving any of the contents of the web page from the specified URL location on the associated web form.

From the following code, it only outputs "Ok" on the web browser.

The web browser I am currently using is Netscape version 4.79, and using Perl version 5.6.1, although the @INC
points to Perl version 5.0.5 on the local web server which I am placing the html, and cgi files on.

The question is that shouldn't print $page place the HTML content of the specified URL on the web browser, and
in my case why doesn't this occur? This also relates all the similar functions within the LWP::Simple module
such as getprint(), getstore(), and head().

When I place the -w switch onto the perl interpreter initial line code, the following warnings are shown and
the perl script doesn't compile and displays a server error on the web browser.

---------------------------------------------------------------------
Unquoted string "lang" may clash with future reserved word at automation1.cgi line 26.
Content-type: text/html

Use of uninitialized value in concatenation (.) or string at automation1.cgi line 25.
Use of uninitialized value in pattern match (m//) at /usr/local/perl5.6/lib/site_perl/5.6.1/LWP/Simple.pm line
292.
Use of uninitialized value in print at automation1.cgi line 47.

---------------------------------------------------------------------


If any one has a solution to this problem, reply back.


---------------------------------------------------------------------
#!/usr/local/perl5.6/bin/perl

# perl script to get remote
# urls and strip them and
# upload them to teamsite

use LWP::Simple qw(!head);
use CGI qw:)standard); # then only CGI.pm defines a head()

my ($url, $lang, $page);

$query = new CGI;

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

process_form();
get_url($url);

# Passes the data from the server,
# and takes them onto the PERL script.

sub process_form {

$url = $query->param(url);
$url = "http://" . $url;
$lang = $query->param(lang);

}

# Retrieves the contents of the
# specified URL.

sub get_url {

$page = get ($_);

if ($page = undef) {
print "Couldn't retrieve $url";
}
else {
print "Ok";
print $page;
}

}
---------------------------------------------------------------------
 
M

Michael Budash

Hon Guin Lee - Web Producer - SMI Marketing said:
Hi,

I am having problems with the following code, in which the get() function
from the LWP::Simple is not
retrieving any of the contents of the web page from the specified URL
location on the associated web form.

From the following code, it only outputs "Ok" on the web browser.

The web browser I am currently using is Netscape version 4.79, and using Perl
version 5.6.1, although the @INC
points to Perl version 5.0.5 on the local web server which I am placing the
html, and cgi files on.

The question is that shouldn't print $page place the HTML content of the
specified URL on the web browser, and
in my case why doesn't this occur? This also relates all the similar
functions within the LWP::Simple module
such as getprint(), getstore(), and head().

When I place the -w switch onto the perl interpreter initial line code, the
following warnings are shown and
the perl script doesn't compile and displays a server error on the web
browser.

---------------------------------------------------------------------
Unquoted string "lang" may clash with future reserved word at automation1.cgi
line 26.
Content-type: text/html

Use of uninitialized value in concatenation (.) or string at automation1.cgi
line 25.
Use of uninitialized value in pattern match (m//) at
/usr/local/perl5.6/lib/site_perl/5.6.1/LWP/Simple.pm line
292.
Use of uninitialized value in print at automation1.cgi line 47.

---------------------------------------------------------------------


If any one has a solution to this problem, reply back.


---------------------------------------------------------------------
#!/usr/local/perl5.6/bin/perl

# perl script to get remote
# urls and strip them and
# upload them to teamsite

use LWP::Simple qw(!head);
use CGI qw:)standard); # then only CGI.pm defines a head()

my ($url, $lang, $page);

$query = new CGI;

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

process_form();
get_url($url);

# Passes the data from the server,
# and takes them onto the PERL script.

sub process_form {

$url = $query->param(url);
$url = "http://" . $url;
$lang = $query->param(lang);

}

# Retrieves the contents of the
# specified URL.

sub get_url {

$page = get ($_);

if ($page = undef) {
print "Couldn't retrieve $url";
}
else {
print "Ok";
print $page;
}

}
---------------------------------------------------------------------

try this:

#----------------------------------------------
#!/usr/local/perl5.6/bin/perl

# perl script to get remote
# urls and strip them and
# upload them to teamsite

use strict;
use LWP::Simple qw(!head);
use CGI qw:)standard); # then only CGI.pm defines a head()

# not needed - you used ':standard'
#$query = new CGI;

print header();

my ($url, $lang) = process_form();

get_url($url);

#----------------------------------------------
sub process_form {
#
# Passes the data from the server,
# and returns them to the caller.
#----------------------------------------------

my $url = "http://" . param("url");
my $lang = param("lang");

return ($url, $lang);

}

#----------------------------------------------
sub get_url {
#
# Retrieves and prints the contents of the
# specified URL.
#----------------------------------------------

my $page = get(shift);

unless ($page) {
print "Couldnt retrieve $url";
}
else {
print "Ok\n";
print $page;
}

}
#----------------------------------------------



hth-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top