[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Emulating AS-like properties in Perl



On Tue, 23 May 2000 22:18:49 -0400, Ronald J Kimball wrote:

>> The real challenge, however, is when you want to know the path to a
>> library file.
>
>Fortunately, that's not too hard to solve either:
>
>
>#!perl
>
>use File::Basename;
>
>print dirname($INC{'File/Basename.pm'}), "\n";
>
># includes the directory File, which contains the file Basename.pm

I wasn't joking.

The problem is that @INC may include relative paths. If your library
file is loaded through such a path, a relative is what is stored in
%INC. File::Basename doesn't seem to help, either.

Example:

#lib demo file include.pl
"Because I say so.";  #  so true ....   ;-)

#! perl -w
# test.pl, save in same folder as include.pl, and run it.
require 'include.pl';
use File::Basename;
chdir '::'; # move one dir up
$\ = "\n";
print dirname($INC{'include.pl'});

__END__

This prints ':' (Unix/DOS people may recoginze this as equivalent to
'.'). Not only is this a relative path; it's wrong, too, because of the
chdir.

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org