Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by Corion (Patriarch)
on Mar 27, 2008 at 09:27 UTC ( [id://676665]=note: print w/replies, xml ) Need Help??


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] ;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://676665]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found