Chris Wagner wrote:

At 01:44 PM 1/12/2006 -0800, Lyle Kopnicky wrote:
If I put a relative path in @INC, I guess it would be relative to the current directory. Which is whatever the directory the console is in when it runs the script. Not very useful for finding modules. Instead I want to find a path relative to where the script is located. (Actually, I'm interested in finding the parent directory of the one where the script is located.) As far as I can tell, there is no function that tells me that. That is why I have to calculate it.

The current directory is automatically in @INC.  If the script and module
are in the same dir then u have to do nothing.

Wrong. The script is not necessarily in the current directory. Let's say you type at the prompt:

 C:\> \devel\perl\project2\main.pl

Then the current directory is 'C:\', but the script is in 'C:\devel\perl\project2\main.pl'. If your modules are all in 'C:\devel\perl\project2\', then you want that path in @INC. But I can't use the literal path, it must be computed, lest I move the project to 'C:\test\project2' or something like that.

 If the the path is always
something known reletive to the current dir u can try use lib "../dir"; or
first find the current dir with use Cwd; and then chopping off the last dir
component and putting the result into @INC.
That's the kind of stuff done by the code I attached. Except it first has to figure out what the script's dir is. What we do know is that $0 is the path to the script, relative to the current dir. Hence the call to File::Spec->rel2abs().

What is the most common way that people handle this? That is, say your modules are in the same folder as the main script. (Which I would think

. is always in @INC.
But, as I said, '.' is not necessarily where the script is. That's why in my script, I computed where the script is, went up one directory, and did a chdir.

--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to