logos

With Andrii Grytsenko


Technical Diary - With Andrii Grytsenko

Use perl module without root access

Take this simple instruction if you need to include module (which is not installed at your system) to your perl script.

  1. Get module and install it to directory where you have write permission (For example: /home/user1/libs).
  2. Go to your script and add new library path to your INC array:
  3. use lib '/home/user1/libs';

    to check that it was successfully put in INC array, print it out

    print "\@INC = @INC\n";
  4. Include it to your script with “require” or “use” directives.
  5. require "test.pm";

    or

    use "test.pm";

SAMPLE

Here is some little sample how it’s work.

Our module:

user1@agrytsenko:~/tmp2$ cat lib/test.pm
package test;

use strict;

sub say {
my $word=shift;
my $str="Hello my $word world\n";
return($str);
}
1;
__END__

Our script:

user1@agrytsenko:~/tmp2$ cat bin/test.pl
#!/usr/bin/perl

use lib '/home/user1/tmp2/lib';
require 'test.pm';

my $string=test::say("good");
print $string, "\n";

Our running result:

sheva@agrytsenko:~/tmp2/bin$ ./test.pl
Hello my good world

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

Translate