Hi Experts,
Please take a look at a small demo program including file structure below:
So we know the executable 'run.pl' can be executed from /tmp/perl.
2nd Q: How do I make it runnable from anywhere?
Thanks!
Please take a look at a small demo program including file structure below:
Code:
[b][VM] perl 25 % pwd[/b]
/tmp/perl
[b][VM] perl 26 % ls -l *[/b]
-rwxr-xr-x 1 test staff 133 2013-09-18 12:20 run.pl*
lib:
total 4
-rw-r--r-- 1 test staff 233 2013-09-18 12:20 utils.pm
[b][VM] perl 27 % cat run.pl[/b]
#!/usr/bin/perl
use strict;
use lib "./lib";
use utils;
print "$0 ... calling utils.pm..my_method()\n";
utils::my_method();
[b][COLOR=red]
# 1st Q: why do I need the name space 'utils::' here? Isn't my_method() a public method?
# If I did use the name space, e.g.
# &my_method(); ## This is line 10
# I'd get this error:
# Undefined subroutine &main::my_method called at ./run.pl line 10.
[/color][/b]
exit;
[b][VM] perl 28 % cat ./lib/utils.pm[/b]
package utils;
use strict;
our (@ISA, @EXPORT);
@ISA = qw(Exporter);
my @publicFunc = (
'my_method',
# more methods here
);
foreach (@publicFunc) {
push @EXPORT, $_;
}
sub my_method {
print "In utils.pm..my_method()\n";
}
1;
[b][VM] perl 29 % ./run.pl[/b]
./run.pl ... calling utils.pm..my_method()
In utils.pm..my_method()
So we know the executable 'run.pl' can be executed from /tmp/perl.
2nd Q: How do I make it runnable from anywhere?
Code:
[b][VM] tmp 32 % pwd[/b]
/tmp
[b][VM] tmp 33 % ./perl/run.pl[/b]
Can't locate utils.pm in @INC (@INC contains: ./lib /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at ./perl/run.pl line 6.
BEGIN failed--compilation aborted at ./perl/run.pl line 6.
Thanks!