Adding an Include Path for a Module to a Simple Perl Tutorial

I am trying to make a simple tutorial, but I am having problems running it. My problem seems to be installing and getting the right module path.

** 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 at Host Gator, they say the following:

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 inclusion 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. Therefore, I added the code, but I have no idea if I added it to the right place.

#!/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 was already convinced that the file has the necessary permissions 755

In addition, LWP :: UserAgent is number 5.835 in the Host Gator. Does this mean that I have to change

LWP 5.64;

LWP 5.835

+3
2

, LWP , BEGIN, LWP ( use strict).

, . , LWP , use LWP;.

+3

Host Gator . lib:

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

script , .

, :

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

perl commaind

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

Source: https://habr.com/ru/post/1749636/


All Articles