hacker has asked for the wisdom of the Perl Monks concerning the following question:
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:
<tmpl> foo = 1 bar = SomeThing blort = 2003-06-29 </tmpl>
I detach this template from the body of the email with Mail::Internet as follows:
my $message = new Mail::Internet ([<>]); my @body = @{$message->body()};
From here, I parse it out with Config::General, and end up with things like this:
my %config = $conf->getall; my $template = $conf->obj('tmpl'); my $foo = $config{'tmpl'}->{'foo'}; my $bar = $config{'tmpl'}->{'bar'}; my $blort = $config{'tmpl'}->{'blort'}; # ... up to 40 possible values
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A Refactoring We Will Go
by adrianh (Chancellor) on Jun 29, 2003 at 19:48 UTC | |
|
Re: A Refactoring We Will Go
by tcf22 (Priest) on Jun 29, 2003 at 17:25 UTC | |
by Anonymous Monk on Jun 29, 2003 at 18:14 UTC | |
by Anonymous Monk on Jun 30, 2003 at 07:17 UTC | |
|
Re: A Refactoring We Will Go
by hacker (Priest) on Jul 01, 2003 at 15:05 UTC | |
by tye (Sage) on Jul 01, 2003 at 15:36 UTC |