On Wed, 16 Oct 2002 [EMAIL PROTECTED] wrote:

> Hi,
> 
> I have a problem when porting an application from Apache 1.23.x + mod_perl
> 1.0 to Apache 2.xx + mod_perl 2.0.
> 
> One of the scripts receives as argument a filename (with no path info), and
> the scripts is suppose to open the file from the same directory in which
> the script is located and perform some stuff on it. 
[ ... ]
> This code used to work on previous platform, i.e. the file called
> "filename" would be opened from the same directory as the script itself.
> Now, the system cannot anymore.  If I hardcode the filename with full path,
> it works (this was to check whether I had some file permission problems).

As you've discovered, assuming a value for the current working
directory isn't reliable. Apart from using the full path, one
possibility is to use FindBin, which gives the directory of the
original script, and you can then specify paths relative to that.
However, the perl-5.8 man page for FindBin warns, in part,

 If there are two modules using "FindBin" from different directories
 under the same interpreter, this won't work. Since "FindBin" uses
 "BEGIN" block, it'll be executed only once, and only the first caller
 will get it right. This is a problem under mod_perl and other persistent
 Perl environments, where you shouldn't use this module. Which also means
 that you should avoid using "FindBin" in modules that you plan to put on
 CPAN. The only way to make sure that "FindBin" will work is to force the
 "BEGIN" block to be executed again:

   delete $INC{'FindBin.pm'};
   require FindBin;

-- 
best regards,
randy kobes

Reply via email to