How to locate my script file itself when it is called by others.

M

MorningStar

I wrote a perl script and it will be called by other modules.
Now I need to know where I(my script) am when I am called.
For example: If my script located in:
/home/morningstar/a.pl
And some one called it from:
[home/someone]$ /home/morningstar/a.pl
or even
[home/someone]$ a.pl (if /home/morningstar is in $PATH ENV)

Then when a.pl was executed, how can it get its location:
"/home/morningstar/"?

If you don't understand what do I mean, just imagin the functionality
of 2 Windows API: GetModuleFileName and GetModuleFileNameEx.

Thanks.
 
J

John W. Krahn

MorningStar said:
I wrote a perl script and it will be called by other modules.
Now I need to know where I(my script) am when I am called.
For example: If my script located in:
/home/morningstar/a.pl
And some one called it from:
[home/someone]$ /home/morningstar/a.pl
or even
[home/someone]$ a.pl (if /home/morningstar is in $PATH ENV)

Then when a.pl was executed, how can it get its location:
"/home/morningstar/"?

perldoc FindBin


John
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top