beermad has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Resolving correct directory path in a symlinked directory
by moritz (Cardinal) on Apr 29, 2011 at 13:02 UTC | |
|
Re: Resolving correct directory path in a symlinked directory
by toolic (Bishop) on Apr 29, 2011 at 13:05 UTC | |
by beermad (Novice) on Apr 30, 2011 at 18:01 UTC | |
|
Re: Resolving correct directory path in a symlinked directory
by jpl (Monk) on Apr 29, 2011 at 13:53 UTC | |
by beermad (Novice) on Apr 30, 2011 at 18:06 UTC | |
by beermad (Novice) on Apr 30, 2011 at 19:24 UTC | |
by afoken (Chancellor) on May 01, 2011 at 07:34 UTC | |
|
Re: Resolving correct directory path in a symlinked directory
by graff (Chancellor) on May 01, 2011 at 18:20 UTC |