
S_Shrum
User
Oct 29, 2001, 6:04 PM
Post #1 of 1
(200 views)
|
|
Let me know if this is a good idea...and how to do
|
Can't Post
|
|
I am in the process of cleaning up a bunch of the code that I wrote. Currently, I have created a series of hashes that store various information about the script such as: DEFAULTS, SCRIPT, and ERRORS. DEFAULTS contains a listing of default values SCRIPT contains script information (version, status, etc). ERRORS contains a list of the various error messages. I am looking to consolodate some of the above (and extent) this into one hash. The thing that I would like to do is have a PARAMETERS hash. In it I would like to have 1. The paramater name 2. A default value (if any) 3. A REQUIRED flag. 4. A error message if required is set but the parameter was not passed. I guess it would look like:
my %PARAMETERS ( name => "delimiter" , default => "|", name => "type", required => "y", name => "sort", name => "order", default => "ascending", ); ( ...I know the code above is wrong but it gives you the general idea... ) I would like to loop though all the required PARAMETERS to be used to trigger a DIE in the event that the user does not supply a value to the name PARAMETER. Currently, anytime I have a parameter that I need to make sure exists, I have to write a eval statement for each parameter. This is a bit tedious and it justs seems wrong. Essentially, this would allow me to define a new parameter in the hash and the code within the script would act accordingly. An example of this that I currently have is:
# set defaults for parameters omitted by user for ( keys Þfaults ) { $input->param(-name=>$_,-value=>$defaults{$_}) unless $input->param($_); } ...which sets the value of a parameter to the default if the value is not set yet. Anybody have any ideas on how to approach this. TIA Sean Shrum sean@shrum.net www.shrum.net
|