Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Checking for undef after performing get()

by sawtooth (Initiate)
on Jan 09, 2006 at 22:06 UTC ( #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(''); $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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://522053]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2017-05-30 03:54 GMT
Find Nodes?
    Voting Booth?