perl package directories - what if the script is diff DIR to the one contain *.pm?

Hi there,

say the package is in the ~/ and it's ~/packageFoo.pm

I can use usePackage.pl in ~/ (~/usePackage.pl).

Now, if I move it to ~/subDIR/usePackage.pl, the script won't work because it's not in the same DIR with packageFoo.pm

How can i fix it?

Thanks

Gusla

Two ways.

Just amend the include path at the top of your script, i.e. @INC

e.g.

@INC = ('..', @INC);

Maybe to cause it to take effect early (before execution) by

BEGIN {
	@INC = ('..', @INC);
}

which is essentially the same as the Perl pragma "use lib" :

e.g.

use lib '..';

More information:
http://theoryx5.uwinnipeg.ca/CPAN/perl/lib/lib.html