Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Finding files relative to a module

by GrandFather (Saint)
on May 15, 2011 at 05:38 UTC ( #904918=note: print w/replies, xml ) Need Help??

in reply to Finding files relative to a module

Looks like you are hoping that catfile( __PACKAGE__, updir(), 'db' ) will find the folder 'db' relative to the folder containg the .pm file. However __PACKAGE__ is Chess::PGN::EPD which is unlikely to be what you mean and updir() removes it in any case so the catfile call is effectively catfile('db') which returns 'db' without the context you seem to be hoping for.

A technique that may help is to look up %INC for the module entry:

my $modulePath = $INC{'Chess/PGN/'};

which will give a relative or absolute path (depending on where the module is) ending in 'Chess/PGN/'. That is, the file name will need to be stripped off the end of the path. Something like the following may work:

... use File::Spec::Functions qw(rel2abs splitpath updir catdir); use Cwd qw(realpath); my $loadPath = rel2abs ($INC{'Chess/PGN/'}); my @parts = splitpath ($loadPath); my $db_dir_qfn = realpath (catdir (@parts[0, 1], updir(), 'db'));
True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://904918]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2021-01-20 21:49 GMT
Find Nodes?
    Voting Booth?