Get Invoked Script Location in Perl

F

fiorentico

Hi,

I'd like to obtain the location of the script I am calling. E.g.

If I am calling

perl X:\script.pl

I want to obtain "X:\". How do I do that?

getcwd and cwd don't apply beacuse I am running the Script from another
location. Thanks
 
D

David Squire

Hi,

I'd like to obtain the location of the script I am calling. E.g.

If I am calling

perl X:\script.pl

I want to obtain "X:\". How do I do that?

getcwd and cwd don't apply beacuse I am running the Script from another
location. Thanks

See perldoc perlvar. Look for the string "Contains the name of the
program being executed".


DS
 
B

Ben Morrow

Quoth "A. Sinan Unur said:
See perldoc FindBin.

AFAIK, the contents of $0 are OS dependent.

They are, and IIRC FindBin doesn't always work on Windows (in
particular, if the program was found through the PATH then $0 contains
just the program name, and FindBin fails). They may have fixed it by
now, of course... :)

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top