crenz has asked for the wisdom of the Perl Monks concerning the following question:

This sounds like a trivial question, but somehow I can't find the answer. I'd like to be able to find out the location of the script file that is being executed by perl. $0 won't do, because it doesn't contain the path. Cwd won't do, because on Mac OS X, the operating system sets the current working directory to /.

Can anyone help me out?

Replies are listed 'Best First'.
Re: Finding out name and path of script file
by Fletch (Bishop) on May 26, 2004 at 23:36 UTC

    Erm, no.

    Darwin lemur.phydeaux.org 7.3.0 Darwin Kernel Version 7.3.0: Fri Mar +5 14:22:55 PST 2004; root:xnu/xnu-517.3.15.obj~4/RELEASE_PPC Power M +acintosh powerpc lemur:~ 604> ( cd /tmp ; perl -MCwd -le 'print getcwd' ) /private/tmp

    Perhaps if you included more details about how you're running it (and see the FindBin module).

      Thanks for your fast reply, Fletch. I knew there must be something, but couldn't find anywhere. FindBin does what I mean. Perfect, thanks!

      As for changing the path, I should have included more context, sorry. I was talking of running GUI applications in Mac OS X ".app" format (and using a perl script as the executable), and not of standalone scripts, of course.