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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for a non-exisiting variable?

Status
Not open for further replies.

Kenny100

Technical User
Feb 6, 2001
72
NZ
Hi Folks

I've got a little Perl program that reads in variables from an external file (config.txt). It uses a simple while loop to extract the contents of config.txt and split the name/values on the = sign.

I'd like to put in some error checking into my program that makes sure that all variables have been included in config.txt. At the moment, if I remove a variable from config.txt I get errors.

Therefore, how can I check that a variable actually EXISTS? Basically I need somethine like:

1. Read in file contents (DONE)
2. Split contents on = sign into name/values (DONE)
3. Check if e.g. $fname exists. If not, set it to a default value and continue.

Can this be done?

Cheers,
Kenny.
 
[tt]$fname = "default.txt" if !defined $fname;[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top