Home > Archive > PERL Beginners > September 2007 > using a perl module
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
using a perl module
|
|
| Perllearner 2007-09-17, 7:59 am |
| I am having a look at cpanel v3 code for using a perl module after
installing it in your user directory (when not root):
my $homedir = (getpwuid($> ))[7];my $n_inc = scalar @INC;for (my $i =
0; $i < $n_inc; $i++ ) { if (-d $homedir . '/perl' . $INC[$i])
{ unshift(@INC,$homedir . '/perl' . $INC[$i]); $n_inc+
+; $i++; }}
However this doesn't work, I came across a website
http://digitalpbk.blogspot.com/2007...nclude-inc.html
that suggests it works with
......
This script dint work for me much, so I manually included the include
locations into the BEGIN segment.
#! /usr/bin/perl -wBEGIN {unshift @INC,"/home/directory/perl/usr/lib/
perl5/site_perl/5.8.7/";}...
I am slightly as to how this is done
there are no email details so I cannot email him direct to find out
how it was done,
I tried amending
my $homedir = (getpwuid($> ))[7];my $n_inc = scalar @INC;for (my $i =
0; $i < $n_inc; $i++ ) { if (-d $homedir . '/perl' . $INC[$i])
{ unshift(@INC,$homedir . '/perl' . $INC[$i]); $n_inc+
+; $i++; }}
so it says
my $homedir = (getpwuid($> ))[7];my $n_inc = scalar @INC;for (my $i =
0; $i <
$n_inc; $i++ ) { if (-d $homedir . '/perl' . $INC[$i]) {
BEGIN {unshift @INC,"/home/directory/perl/usr/lib/perl5/site_perl/
5.8.8/";} $n_inc++; $i++;
}}
still can't find the module
I also tried his suggested begin{...} include statements with and
without the above code and still no luck with perl finding the module,
even though the module is correctly installed in my directory, any
help to get perl to recognise the module will be greatly appreciated.
thanks in advance
| |
| Jeff Pang 2007-09-17, 7:59 am |
| 2007/9/17, perllearner <cashback103@dodgeit.com>:
> I am having a look at cpanel v3 code for using a perl module after
> installing it in your user directory (when not root):
>
> my $homedir = (getpwuid($> ))[7];my $n_inc = scalar @INC;for (my $i =
> 0; $i < $n_inc; $i++ ) { if (-d $homedir . '/perl' . $INC[$i])
> { unshift(@INC,$homedir . '/perl' . $INC[$i]); $n_inc+
> +; $i++; }}
>
> However this doesn't work
Hi,
I just tested the codes above,they can work fine,thought they're
written with bad style.
Add these lines into your script:
BEGIN {
my $homedir = (getpwuid($> ))[7];
my $n_inc = scalar @INC;
for (my $i =0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;
}
}
}
And be sure you have created your own module dirs.
From what the codes doing,your own module dirs should properly be located in:
$homedir/perl/perl_module_system_dirs
you can,
use Data::Dumper;
print Dumper \@INC;
to see what's perl_module_system_dirs on your OS.
| |
| Rob Coops 2007-09-17, 7:59 am |
| This is the code that works for me:
my $homedir = (getpwuid($> ))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;
}
}
The reason for it working is because my perl modules that I install via
cpanel are installed in /home/<username>/perl/
You seem to be installing them in:
/home/directory/perl/usr/lib/perl5/site_perl/5.8.8/
It very much looks like your problem stems from that, I cannot verify this
as I do not have access to my own box from work (yes security is pretty
decent over here), but I would guess then using data dumper and printing the
@INC variable you should be able to figure out where things are going wrong.
So after your include statment write the following:
use Data::Dumper;
print Dumper @INC;
This should get you a list that looks a little like this:
$VAR1 = '/usr/local/lib/perl5/5.8.8/i686-linux';
$VAR2 = '/usr/local/lib/perl5/5.8.8';
$VAR3 = '/usr/local/lib/perl5/site_perl/5.8.8/i686-linux';
$VAR4 = '/usr/local/lib/perl5/site_perl/5.8.8';
$VAR5 = '/usr/local/lib/perl5/site_perl';
$VAR6 = '.';
As you can see this is a different box and as such it will most likely be
different for you as well but at least you will be able to find where perl
is looking for the modules.
Hope it helps, regards,
Rob
Now this is exactly what our fine cpanel v3 is suggesting and the reason for
it working is because:
1) My prompt is
On 9/17/07, perllearner <cashback103@dodgeit.com> wrote:
>
> I am having a look at cpanel v3 code for using a perl module after
> installing it in your user directory (when not root):
>
> my $homedir = (getpwuid($> ))[7];my $n_inc = scalar @INC;for (my $i =
> 0; $i < $n_inc; $i++ ) { if (-d $homedir . '/perl' . $INC[$i])
> { unshift(@INC,$homedir . '/perl' . $INC[$i]); $n_inc+
> +; $i++; }}
>
> However this doesn't work, I came across a website
>
> http://digitalpbk.blogspot.com/2007...nclude-inc.html
>
> that suggests it works with
> .....
>
> This script dint work for me much, so I manually included the include
> locations into the BEGIN segment.
>
>
> #! /usr/bin/perl -wBEGIN {unshift @INC,"/home/directory/perl/usr/lib/
> perl5/site_perl/5.8.7/";}...
>
> I am slightly as to how this is done
>
> there are no email details so I cannot email him direct to find out
> how it was done,
>
> I tried amending
>
> my $homedir = (getpwuid($> ))[7];my $n_inc = scalar @INC;for (my $i =
> 0; $i < $n_inc; $i++ ) { if (-d $homedir . '/perl' . $INC[$i])
> { unshift(@INC,$homedir . '/perl' . $INC[$i]); $n_inc+
> +; $i++; }}
>
> so it says
>
> my $homedir = (getpwuid($> ))[7];my $n_inc = scalar @INC;for (my $i =
> 0; $i <
> $n_inc; $i++ ) { if (-d $homedir . '/perl' . $INC[$i]) {
> BEGIN {unshift @INC,"/home/directory/perl/usr/lib/perl5/site_perl/
> 5.8.8/";} $n_inc++; $i++;
> }}
>
> still can't find the module
>
> I also tried his suggested begin{...} include statements with and
> without the above code and still no luck with perl finding the module,
> even though the module is correctly installed in my directory, any
> help to get perl to recognise the module will be greatly appreciated.
> thanks in advance
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
|
|
|
|
|