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

I have a cgi script that uses LWP::UserAgent to get some weather information from a National Weather Service web site and then displays certain pieces in my format. It is not on the web server I originally created it on, but it worked fine when I transferred it. I started getting errors in the web log with the script and did some investigating. It turned out the problem was with the NWS web page and the script is now working again.

However, when I started testing it I tried running the script from a Unix prompt and I got the following error message:

Can't locate LWP/UserAgent.pm in @INC (@INC contains: /usr/local/lib/perl5/5.8.0/sun4-solaris-thread-multi /usr/local/lib/perl5/5.8.0 /usr/local/lib/perl5/site_perl/5.8.0/sun4-solaris-thread-multi /usr/local/lib/perl5/site_perl/5.8.0 /usr/local/lib/perl5/site_perl .) at weather.pl line 9.  BEGIN failed--compilation aborted at weather.pl line 9.

I am not at all familiar with perl module installation mainly because I have no control over the modules on the server I'm using. I got some information about the perl modules on the server and found out that the perl version installed is RPM:perl-5.00502-18 and has been that version since March 2002, the only updates being to the File::Spec and GD modules.

One of my questions is, why is my script looking for LWP in /usr/local/lib/perl5/5.8.0? At the top of my script I have #!/usr/bin/perl -Tw and line 9 that generates the error is use LWP::UserAgent;.

Also, since the error message says "BEGIN failed--compilation aborted", why is the script actually working on the web page?

Replies are listed 'Best First'.
Re: Can't locate LWP/UserAgent.pm
by larsen (Parson) on Aug 05, 2003 at 14:29 UTC
    I'm a bit confused. Here what I've understood: there's a CGI script that has some problems, so you tried it from the command line, where it gives compilation errors due to lack of LWP::UserAgent. My suspect is that you have two version of Perl on that machine. One is /usr/bin/perl, which is used by the script when run through the webserver, and the other one is /usr/local/bin/perl, which is being called when you type perl from the command line. The latter has not LWP::UserAgent installed. You can verify my suspect typing:

    which perl

    at the command prompt.
      I typed which perl at the command prompt and got /usr/opt/bin/perl.

      I changed the first line of my script to
      #!/usr/opt/bin/perl -w
      and tried running it again. I got the same error message:

       Can't locate LWP/UserAgent.pm in @INC (@INC contains: /usr/local/lib/perl5/5.8.0/sun4-solaris-thread-multi /usr/local/lib/perl5/5.8.0 /usr/local/lib/perl5/site_perl/5.8.0/sun4-solaris-thread-multi /usr/local/lib/perl5/site_perl/5.8.0 /usr/local/lib/perl5/site_perl .) at weather.pl line 9.  BEGIN failed--compilation aborted at weather.pl line 9.

      The script continues to work on the web page.

        K,

        It looks as though @INC for you doesn't include a version of perl with LWP::UserAgent.pm installed, whereas @INC for the webserver (usually 'nobody') does use a version of perl with the module.

        First off, run this cmd: locate perl | more That will show you all the places where perl is installed on the machine. My suspicion is that you have two versions of perl installed: 5.8.x is installed for users, and the web server is using some other version. If so, you'll see this kind of thing (minus my comments w arrows):

        ... /usr/lib/perl5/5.6.0 <--- version 5.6.0 of perl ... /usr/local/lib/perl5/5.6.1/CGI.pm <--- diff version --More--

        Edit: I didn't notice that you said the webserver is using 5.005x. Teach me not to read carefully.

        You (meaning your user account) seems to be using 5.8.x, which has no LWP::UserAgent.pm installed.

        You haven't said why you've decided to test this CGI script by running it from the command line, but you might consider using CGI::Carp, which will send error messages to the browser. And since it will be running as the web server, it will execute using the 5.005x version of perl that has LWP.

        Another solution is to remove the 5.8x version of perl from your $PATH variable, and add the 5.005x version. To do so, you'll have to find the 5.005x version--use 'locate perl | grep "5.005" | more; or something similar, and add the path to the 5.005 interpreter to your $PATH.

        AH

        for this install libwww-perl this will fix it ask Admin to do it