Parse::RecDescent and autotree

Tom Phoenix rb-pdx-pm at
Mon Jun 17 14:24:38 CDT 2002

On Mon, 17 Jun 2002, Colin Kuskie wrote:

> > > use lib '~/perl/modules';
> >
> > Does that do anything useful?
> Actually, since P::RD isn't installed anywhere else aside from my
> private modules directory, it does something very useful, and it works
> :)

Huh? At least one of us is confused. Let's see whether it's me. :-)

My contention is that that line does not make Perl look in a subdirectory
of your home directory for modules, although it pretends to do that.
Instead, it looks in your _current_ directory for a directory with the
unlikely name of '~'. If that's not found (and I suspect it's not) it goes
on to search the rest of your @INC. (So, if perl is finding your modules,
my contention is that it would do so even without this line. Maybe your
module dir is listed in your default @INC, or in the PERL5LIB environment
variable, for example. Of course, you could comment-out the 'use lib'
line to find out whether it's really needed.)

If using a tilde like this in 'use lib' is supposed to work, it's not
documented anywhere that I can find.

How could we test this? Hmmm... Well, if ~ is your home dir, and if it's
not nested more than three directories below the root dir, then
~/../../../ should be synonymous with the root dir. (Try 'ls ~/../../../'
to see what I mean.) So, here's some code:

    #!/usr/bin/perl -w

    my $root_dir;

    BEGIN {
	$root_dir = '~/../../../';
	# Here's the fixer:
	# $root_dir =~ s#~#$ENV{HOME}#;
	for (@INC) {

    use lib '~/perl/modules';
    print "Yep, that worked: $root_dir is a synonym of the root dir.\n";

On my system, it fails as expected. If I uncomment the "fixer", it works.
Do you see something different on yours? (You may need to change the
"fixer" if you don't have a $HOME environment variable. And if your
homedir is in /mnt/remote/offsite/somewhere/else/users/yeah/right, you'll
need to add a few more dot-dots to $root_dir in the first place.)

(Aside for the adventurous: Consider the command 'ln -s ~ ./~'. That is
another way to make this program work, but don't do it unless you know
what it does and how to undo it.)

> However, it still doesn't explain why P::RD doesn't work as advertised.
> Maybe I should send this over to Dr. Conway and see what shakes.

Good idea. It's probably all his fault. :-)

--Tom Phoenix


More information about the Pdx-pm-list mailing list