Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can you make a perl program read its own file name?

Status
Not open for further replies.

supernova83

Programmer
Joined
Nov 12, 2006
Messages
3
Location
RO
I have about 20 perl programs that are very similiar - only the values of about 10 variables are different (and maybe a few conditions will change according to these values).
There is also a file in which there are more sets of variable values, each associated to a perl program.

I would like to be able to read the program's name from within the program - so that these associations will be made automatically. And I don't know how to do that.

Thank you.

[my current approach was to have all these programs generated from another program, but I want to change it]
 
You can get the name of the program being executed from the special $0 variable. This will probably contain some path information in addition to just the name of the script. You could use File::Basename to extract the script's name from it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top