Chris Share wrote:
Rob Dixon wrote:
Chris Share wrote:

I'm trying to implement the following code:

######################################################

require LWP::UserAgent;

 my $ua = LWP::UserAgent->new;
 $ua->timeout(10);
 $ua->env_proxy;

 my $response = $ua->get('http://search.cpan.org/');

 if ($response->is_success) {
     print $response->content;  # or whatever
 }
 else {
     die $response->status_line;
 }

######################################################

The code works but what I don't get is how do I know if LWP::UserAgent (or even LWP) is installed on my machine.

If I use the Perl Package Manager and type: query LWP
I get the following:

Querying target 1 (ActivePerl 5.8.7.815)
1. LWP-UserAgent-Determined [1.03] a virtual browser that retries errors

This is a module (?) I installed myself.

Is LWP::UserAgent installed--I guess it must be because the code works.

Can someone explain this?


First of all it should be

use LWP;

which does the 'require LWP::UserAgent' for you as well as checking that you're running on an adequate version of Perl and setting the LWP version number.

And you can find out whether LWP is installed by entering

perl -MLWP -e"1"

on the command line. It will shout if the module isn't there. Your program will also die at the require if it doesn't find LWP::UserAgent, saying something like
'Can't locate LWP/UserAgent.pm in @INC'.
>
> Thanks for the info. Isn't this what the Perl Package Manager is for?


Hi Chris. Please bottom-post your replies. Thanks.

Perl Package Manager is an ActiveState utility that will tell you only what
packages it remembers installing itself. It won't tell you about anything that
you've installed with CPAN or even anything that was installed with Perl itself,
like List::Utils. And if it has been used to install a package which has since
been damaged or deleted behind its back it will happily tell you that it;s still
there. Using Perl itself to try to load the module as I described is the best
test.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to