lunedì 7 giugno 2010

Perl: using script anywhere in your filesystem

How many times, writing perl script, you have seen this ugly message:

[danimoth@jim test]$ ./TestFileGetCmd.pl
Can't locate FileGetCmd.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.10.1 /usr/share/perl5/site_perl/5.10.1 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl /usr/lib/perl5/current /usr/lib/perl5/site_perl/current .) at ./TestFileGetCmd.pl line 5.
BEGIN failed--compilation aborted at ./TestFileGetCmd.pl line 5.
...

To remove this, you could simply add at the beginning of the script:

use lib 'your_dir';

..and you're OK.

Note that 'your_dir' is relative (so, don't use ../../ or similar if you expect your script is executed from various filesystem's point but instead use absolute path).

If you're sure your scripts will be executed from a specified dir, you could safely use "..".

HTH,