go ahead... be a heretic | |
PerlMonks |
A Refactoring We Will Goby hacker (Priest) |
on Jun 29, 2003 at 16:03 UTC ( [id://269996]=perlquestion: print w/replies, xml ) | Need Help?? |
hacker has asked for the wisdom of the Perl Monks concerning the following question:
I've got a script that is part of a larger collection of "tools" I use on a cron'ly basis for mirroring and administration of some distributed servers in a cluster, and it basically wraps a system binary which takes roughly 40 possible arguments.
What I've got thus far, is modified via an email sent to a specific (secured) account on an internal control box. In this email body is a template, pseudo-XML, which contains the options I want to pass to the system binary in 'key = value' pairs, and looks like this:
I detach this template from the body of the email with Mail::Internet as follows:
From here, I parse it out with Config::General, and end up with things like this:
When I have these all in scalars, I go through them one-by-one, and validate each, to make sure I didn't pass any typos or other invalid values. for example, the key 'foo' in the template can only take a digit, so I can restrict that, and check it. The next key, 'bar' may only take a common word, starting with a capital letter. I can also check that. You can see how lengthy this gets after 40 possible values need to be stuffed into scalars and checked for proper syntax and validity. Is there a better way to parse, accept, and validate each of these values from the template, without duplicating 40 separate checks for each value that can be passed?
Back to
Seekers of Perl Wisdom
|
|