Re: Perl

From: Tony Arkles <tony_at_no.spam.please>
Date: Fri Jul 21 2006 - 01:20:48 CST

On 20-Jul-06, at 3:52 PM, Greg Oster wrote:

> "Steven Kurylo" writes:
>> Here is the problem. I have a large hash which looks something
>> like this:
>>
>> %networks = (
>> 'name' => {
>> filter => 'net 10.10.10.0/21',
>> port => '234',
>> },
>> );
>>
>
> Take a step back from things, and let the code be code, and the data
> be data? (vs. doing the "data as code"?) (i.e. define a format for
> a configuration file, and read+parse that file to build up %networks )
>
> Once you decide on a format for the config/data file, it'd be easy to
> write a perl script to convert your existing "data as code" into just
> the necessary data bits :)

I don't want to come across as a big XML hater, but several of the
other replies have reminded me of a quote: "Let's say you have a
problem and you decide to solve it using XML. Now you have two
problems."

Depending on how elaborate your filter specification has to be, it
would probably be possible to just do a regex on a simple text file.
Say each entry looks like:

network NAME HERE filter FILTER SPEC HERE port PORT

then you could read each line and check it with a regex like:

$inputline =~ /network (.*?) filter (.*?) port (.*?)$/

and have your name, filter spec, and port returned into $1, $2, and
$3, assuming that your filter spec will never have the word 'port' in
it.

I'll admit that this is a very simplistic solution, but a lot of
times that's all you need :).
Received on Fri Jul 21 01:20:59 2006

This archive was generated by hypermail 2.1.8 : Fri Sep 08 2006 - 23:26:38 CST