I am writing a Perl script which does -
- SSH to one of the server and do some operation using
- I want to have entire log of the script to be stored in certain log file using
- I want to write some data to CSV file using
Actually these three Perl Modules have been installed in different directories.
Lets say -
Net::OpenSSHis installed in /path/to/lib1
Log::Log4perlis installed in /path/to/lib2
Text::CSVis installed in /path/to/lib3
Since these Perl Modules has been installed in different locations, I am mentioning the respective paths in Shebang line like below:
#!/usr/bin/perl -I/path/to/lib1 -I/path/to/lib2 -I/path/to/lib3 use strict; use warnings; use Net::OpenSSH; use Log::Log4perl; use Text::CSV; #continue flow of the script ..
This works perfectly fine for me.
I found one more method to call these Perl modules like below:
#!/usr/bin/perl use strict; use warnings; use lib '/path/to/lib1'; use lib '/path/to/lib2'; use lib '/path/to/lib3'; ...
Above method also works fine for me.
I found the standard way to call these Perl modules by the use of FindBin.
I am confused with its syntax. How can I achieve same using
FindBin Perl Module.
#!/usr/bin/perl use strict; use warnings; use FindBin qw($Bin); use lib "$Bin/path/to/lib1"; use lib "$Bin/path/to/lib2"; use lib "$Bin/path/to/lib3"; ...
This throws me following error which doesn't appears when I use first two methods (Method1, Method2).
unable to load Perl module IO::Pty: Can't locate IO/Pty.pm in @INC ...
Where I am doing wrong in Method 3?
$RealBin is the directory in which the script is located. (
$Bin is a broken version of the same thing.)
If there's no relationship between the directory in which the script is located and the directory in which the modules are located, it doesn't make sense to use
$RealBin. In fact, it usually makes more sense to use the
PERL5LIB env var than
use lib in such cases.
On the other hand, if the script was located in
/path/to/bin, it might make sense to use
use lib "$RealBin/../lib1", "$RealBin/../lib2", "$RealBin/../lib3";