I need to re-use a common cgi-bin subdirectory for a number of websites I'm developing on my server. So the logical method would be:

$ mkdir /www/common/cgi-bin $ cd /www/site1 $ ln -s /www/common/cgi-bin $ cd /www/site2 $ ln -s /www/common/cgi-bin

which works perfectly, EXCEPT that in order to extract site-specific parameters, the cgi scripts need to read files in each individual site's own directory structure. But when resolving relative paths (I can't use absolute because of the nature of the eventual deployment environments) or even the current directory itself, my Perl scripts consider themselves to be in the original directory, not the one it SHOULD think it's in. To clarify:

#!/usr/bin/perl # whereami.pl use Cwd; print(cwd / "\n");
$ cd /www/global/cgi-bin $ whereami.pl /www/global/cgi-bin $ cd /www/site1/cgi-bin $ whereami.pl /www/global/cgi-bin

Similarly, trying to open a file with a relative path from /www/site1/cgi-bin fails because Perl's trying to open it relative to /www/global/cgi-bin.

So, is there a way to either resolve the "correct" path to the current directory in this situation, or at least to persuade it to open files with relative paths as I need?

The problem seems to be as much related to the Linux filesystem as to Perl itself, as

$ cd /www/site1/cgi-bin $ ls ..

Shows the contents of /www/global, not /www/site1.

Thanks in advance for any suggestions.


In reply to Resolving correct directory path in a symlinked directory by beermad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.