<?xml version="1.0" encoding="windows-1252"?>
<node id="904918" title="Re: Finding files relative to a module" created="2011-05-15 01:38:28" updated="2011-05-15 01:38:28">
<type id="11">
note</type>
<author id="461912">
GrandFather</author>
<data>
<field name="doctext">
&lt;p&gt;Looks like you are hoping that &lt;c&gt;catfile( __PACKAGE__, updir(), 'db' )&lt;/c&gt; 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 &lt;c&gt;updir()&lt;/c&gt; removes it in any case so the catfile call is effectively &lt;c&gt;catfile('db')&lt;/c&gt; which returns 'db' without the context you seem to be hoping for.&lt;/p&gt;
&lt;p&gt;A technique that may help is to look up %INC for the module entry:&lt;/p&gt;
&lt;c&gt;
my $modulePath = $INC{'Chess/PGN/EPD.pm'};
&lt;/c&gt;
&lt;p&gt;which will give a relative or absolute path (depending on where the module is) ending in 'Chess/PGN/Moves.pm'. That is, the file name will need to be stripped off the end of the path. Something like the following may work:&lt;/p&gt;
&lt;c&gt;
...
use File::Spec::Functions qw(rel2abs splitpath updir catdir);
use Cwd qw(realpath);

my $loadPath   = rel2abs ($INC{'Chess/PGN/EPD.pm'});
my @parts      = splitpath ($loadPath);
my $db_dir_qfn = realpath (catdir (@parts[0, 1], updir(), 'db'));
&lt;/c&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-461912"&gt;
True laziness is hard work
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
904908</field>
<field name="parent_node">
904908</field>
</data>
</node>
