You have two problems:
-I
doesn't apply to files specified on the command line, only to modules loaded with require
or use
.
You shouldn't use relative directories with -I
. If your script does a chdir
, then that directory is now relative to the new current directory, not the one that was current when the script started. (In many cases, you can get away with breaking this rule, because most of the time, modules are loaded as the script starts, before it has changed directories.)
And you aren't actually using a relative directory anyway, because you said -I/p2
, which means to look in a directory named /p2
, not in a subdirectory named p2
in the current directory (which is what you wanted to say).
Try:
perl -I$PWD/p2 p2/maxconnect4.pl arg1 arg2 arg3 arg4
(assuming you're using a Unix-type shell).
In many cases, a better solution is to have the script set up @INC
automatically. At the top of p2/maxconnect4.pl
(before you load any modules from p2
, put):
use FindBin;
use lib $FindBin::Bin;
use lib
is the programmatic version of the -I
switch, and FindBin tells your script the pathname of the directory in which it is located. Then you can just say:
perl p2/maxconnect4.pl arg1 arg2 arg3 arg4
and not have to bother with -I
at all.