Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > LWP::Simple get() problem

Reply
Thread Tools

LWP::Simple get() problem

 
 
Hon Guin Lee - Web Producer - SMI Marketing
Guest
Posts: n/a
 
      09-26-2003
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;
}

}
---------------------------------------------------------------------
 
Reply With Quote
 
 
 
 
Michael Budash
Guest
Posts: n/a
 
      09-26-2003
In article <(E-Mail Removed)>,
Hon Guin Lee - Web Producer - SMI Marketing <(E-Mail Removed)> wrote:

> 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-

--
Michael Budash
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments