LWP::Simple get() problem

Discussion in 'Perl Misc' started by Hon Guin Lee - Web Producer - SMI Marketing, Sep 26, 2003.

  1. 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;
    }

    }
    ---------------------------------------------------------------------
     
    Hon Guin Lee - Web Producer - SMI Marketing, Sep 26, 2003
    #1
    1. Advertising

  2. In article <>,
    Hon Guin Lee - Web Producer - SMI Marketing <> 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
     
    Michael Budash, Sep 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hon Guin Lee - Web Producer - SMI Marketing

    LWP::Simple get() refined problem

    Hon Guin Lee - Web Producer - SMI Marketing, Sep 29, 2003, in forum: Perl Misc
    Replies:
    6
    Views:
    155
    Bart Lateur
    Sep 30, 2003
  2. Hon Guin Lee - Web Producer - SMI Marketing

    LWP::Simple get() problem

    Hon Guin Lee - Web Producer - SMI Marketing, Sep 29, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    275
    Hon Guin Lee - Web Producer - SMI Marketing
    Sep 29, 2003
  3. Paul E Collins

    Strange timeout with LWP::Simple::get

    Paul E Collins, Sep 22, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    226
    Paul E Collins
    Sep 22, 2004
  4. Replies:
    2
    Views:
    140
    Peter J. Holzer
    Jul 21, 2007
  5. Replies:
    0
    Views:
    107
Loading...

Share This Page