Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Checking for undef after performing get()

by sawtooth (Initiate)
on Jan 09, 2006 at 22:06 UTC ( [id://522053]=perlquestion: print w/replies, xml ) Need Help??

sawtooth has asked for the wisdom of the Perl Monks concerning the following question:

Greetings honorable Monks. I am submitting some information directly from one Perl program located on a local client to another Perl program located on a web server. I need to verify that this information was successfully passed to the Perl program located on a web server. The code works and submits information successfully to the web server, but I have been unable to verify this from the client side program. Example snippet of the functioning code:
use strict; use LWP::Simple; use URI::URL; my $url=url('http://www.webaddress.com/cgi-bin/XXX.pl'); $url->query_form( name => $name, address => $address, email => $email, reading => $reading, ); get($url);
This submits the information and everything works fine on the web server the way that it should. Now, the LWP::Simple docs say that the get() function returns undef if it fails. I have been unable to find a combination of code that works. Among them, after the above snippet:
if (!defined (get($url))){ print"Failed: $^E\n}
Does not work. I am sure that this is simple, however, this is my first voyage into the land of libwww-perl. Please and thank you!

Replies are listed 'Best First'.
Re: Checking for undef after performing get()
by trammell (Priest) on Jan 09, 2006 at 22:20 UTC
    get() doesn't set $!, so your "bad file descriptor" error message is a red herring.
      That doesn't surprise me, but any ideas regarding the question itself?
        Sure; I'd do something like:
        my $doc = get(...); warn "get() failed" unless $doc;
        I'm assuming that the page actually has content here. If it's an empty string, the test should be
        ... unless defined($doc);
        The documenation in LWP::Simple does suggest using LWP::UserAgent if you need more information about the return code. Just a thought.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://522053]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-19 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found