Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Finding files relative to a module

by GrandFather (Sage)
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]
[marto]: FWIW, people shipping things as perl, which aren't strictly perl can cause confusion (Perl and OpenWrt - where to the communities intersect?)
[marto]: cpanm is lighter on resources than cpan, which is handy when working with consumer grade NAS hardware

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-03-17 13:21 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (224 votes). Check out past polls.