[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] the directory where the script is running



At 20:29 -0400 5/18/99, Chris Nandor wrote:
> At 19.26 -0400 1999.05.18, William H. Asquith wrote:
>>How do I determine the directory of the running script on-the-fly?
>
> Current directory is where the script is.  It defaults to MacPerl's
> location if the script is not saved to a file.

If you want a _portable_ solution, however... it gets harder.

Because the Mac doesn't really have a notion of "current" directory, it's
convenient to map "where the script is" to current directory. So "where the
script is" is "where we are" on a Mac. That's nice. Unfortunately in other
Perls, this won't work; the current directory is generally _not_ where the
script is.

If a script starts with #!...perl  AND the script is on Unix AND the script
is on your path or named by an absolute pathname, then $0 will contain the
full path to the script.

If the script is called by a relative pathname, then $0 contains that
relative path (and you have to figure out the location by where it is in
terms of the current directory.)

- Vicki
-- --
       |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
 ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
      |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
     '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.org

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org