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

How to call parameters from a separate file?

Status
Not open for further replies.

webgeo

Technical User
Mar 4, 2003
4
RO
I have a Perl script into which I would like to call different sets of parameters depending on the input.

e.g.

command: myscript.pl [parameter_file_name]

where [parameter_file_name] is one of:
myparameters_1.pl
myparameters_2.pl
etc...

each file containing parameters of the form:
Code:
$parameter1 = value1;
$parameter2 = value2;
etc...

How do I call the myparameters files into myscript.pl and parse the parameters into a useable format? Is there an "elegant" way of doing this without resorting to:

Code:
@line = split("=",$_);
if ( $line[0] eq "parameter1" ) { $parameter1 = $line[1]; }
if ( $line[0] eq "parameter2" ) { $parameter2 = $line[1]; }
etc...

I'm not sure I explained myself very well there but any help would be much appreciated...

Thanks in advance!
 
One way to do it would be to store your parameters in a hash instead of individual variables and do something like:

[tt]@line = split("=", $_);
$params{$line[0]} = $line[1];
[/tt]

Before doing that you would want to initialize the hash so that all of the parameters had default values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top