4

I'm trying to do a simple tutorial but I'm having trouble getting started. My problem seems to be installing and getting the correct path to the modules.

**1. Here is the original code:*****

#!/usr/bin/perl -w
use strict;
use LWP 5.64;

my $browser = LWP::UserAgent->new;
my $url = 'http://www.cspan.org/RECENT.html';
my $response = $browser->get($url);

die "Can't get $url -- ", $response->status_line
    unless $response->is_success;

my $html = $response->content;
while( $html =~m/<A HREF=\"(.*?)\"/g ) {
    print "$1\n";

2. But in Host Gator they say this:

Location of Your Perl Module(s)

Path: /home/d********n/perl

Using Your Perl Module(s)

You will need to add /home/d********n/perl to the include path. You can do this by adding the following code to your script:

BEGIN {
    my $base_module_dir = (-d '/home/d********n/perl' ? '/home/d********n/perl' : ( getpwuid($>) )[7] . '/perl/');
    unshift @INC, map { $base_module_dir . $_ } @INC;
}

3. So I added the code but have no idea if I added it in the correct spot.

#!/usr/bin/perl -w
use strict;
use LWP 5.64;

BEGIN {
    my $base_module_dir = (-d '/home/d********n/perl' ?

'/home/d********n/perl' : ( getpwuid($>) )[7] . '/perl/');
    unshift @INC, map { $base_module_dir . $_ } @INC;
}


my $browser = LWP::UserAgent->new;
my $url = 'http://www.cspan.org/RECENT.html';
my $response = $browser->get($url);

die "Can't get $url -- ", $response->status_line
    unless $response->is_success;

my $html = $response->content;
while( $html =~m/<A HREF=\"(.*?)\"/g ) {
    print "$1\n";

Any help would be greatly appreciated.

FYI, I already made sure the file has the needed permissions 755

Also the LWP::UserAgent has a number of 5.835 in Host Gator. Does that mean I have to change

use LWP 5.64;

to

use LWP 5.835

1
  • Glad to see you were able to get this posted. Commented Jun 11, 2010 at 16:48

3 Answers 3

3

Assuming you've got LWP installed in your local module directory, put the BEGIN block before you try to load LWP (right after use strict).

The version number in the original code indicates that it's the minimum required version. Since you've got a newer version and LWP's interface is stable, a simple use LWP; will suffice.

Sign up to request clarification or add additional context in comments.

2 Comments

If he's adapting someone else's script, that 5.64 is there for a reason. Could you at least mention that it is a minimum required version in your answer?
But to answer his question, he doesn't need to chnage the version number. It would havce been clearer if the original tutorial said use LWP 5.64 ;# We need version 5.64 or later
2

The solution Host Gator seems a bit complicated. I would use the lib module :

use strict ;
use lib '/home/d********n/perl' ;
use LWP ;

If you are running the script from a command line there are two ways you can run it unchanged.

Set it as an environment variable by typing following at command line :

export PERL5LIB=/home/d********n/perl 
myscript.pl

or add it as an option to the perl commaind

perl -I/home/d********n/perl myscript.pl

5 Comments

Thanks, I tried the first option but it didn't work: wildxtremes.com/cgi-bin/Tutorial14f.cgi The other 2 options are way above my head. Can you explain where they would be put in the code? Thanks again
Also the cgi-bin is not in the root directory, it is in a sub directory for another website, could that change the Include Path?
Can you give us a little more detail that "didn't work". If run from the command line, what is the error message produced. If it is a CGI script what gets written to the server log.
You didn't say you were running it as CGI. It doesn't looks as if it was meant to be used that way because it doesnt produce any HTTP headers or format the output in HTML.
AH, now I feel stupid but at least I'm making progress. Thanks for your help.
0

Or directly on the command line using perl option parameter flag -I for eg. multiple directories/projects also with a general module

perl -I'../project/lib' -I'../otherProject/lib' -I'lib' -M'Test::Doctest'  -e run lib/MyOwnModule.pm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.