in reply to How could you make a script think it's running in its own directory?

I prefer File::Basename for that:

use File::Basename; my $base = dirname $0; chdir $base or warn "Couldn't find base directory '$base'. Using current direc +tory.";

This fails if you have weirdo symlinks pointing around. There is FindBin which goes through weird contortions to cover special cases but opens up other venues of failure cases.

  • Comment on Re: How could you make a script think it's running in its own directory?
  • Download Code

Replies are listed 'Best First'.
Re^2: How could you make a script think it's running in its own directory?
by Anonymous Monk on Mar 27, 2008 at 09:28 UTC
    __FILE__?
      How does __FILE__ help? Would you use it with chdir?
      ........
      Those are my principles. If you don't like them I have others.
      -- Groucho Marx
      .......

        Just Try It ...

        use File::Basename qw/ fileparse /; print join "\n" , __FILE__ , ( fileparse __FILE__ )[1] ;