Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

which module to read configuration file?

4 views
Skip to first unread message

lee

unread,
Aug 30, 2014, 2:38:45 PM8/30/14
to begi...@perl.org
Hi,

is there a module available to read configuration files which are like
this:


arbitrary_denominator-00 | alternate-denominator-00 | alternate-denominator-01 [| ...]
{
itemA = <some string>
itemB = <some integer>
itemC = <some float>
itemD = <some CSV>
}


as in:


postm...@example.com
| us...@example.com
{
itemB = 5
itemC = 3.2
itemD = foo, bar, example
}


The "arbitrary_denominator" would allow to retrieve the configuration
options given for that particular thing (in this case an email
address).

It doesn't /have/ to be exactly like this; I simply used a way of
writing it which I'd find pretty. I merely want to kinda have a unique
handle of a set of options that apply so that I can access those in my
script, like:


my $foo = '.*@example.com';
my $config = getconfig->new("some.file");

foreach my $denom (@config->denominators) {
if($denom =~ m/$foo/) {
my $thisitem = config->itemC[$_];
print "itemC of $denom: $thisitem\n" if defined($thisitem);
}
}


I hope you get the idea ... I'm thinking something like Getopt::Long,
but for configuration files like above instead of commandline options.

I don't want to use something like a CSV file for this because each
entry must not be required to have every possible item defined, and a
CSV file would be rather difficult to maintain.


It would be possible, though inconvenient, to use a single file for each
denominator. I think that at the minimum, one file per /array of
denominators/ might do. However, with multiple files, all of them would
have to be examined every time a config item for a denominator is
requested, which could lead to somewhat poor performance, hence I'd
rather use a single file.

This would be one step along the way of solving the problem of printing
(pre-filtered) incoming email, including the attachments, by various
criteria ("when xx sends a PDF then print it unless it has more than N
pages and print all HTML from xx, but print all PDF from xx when the
subject is "foo"; never print the PDF sent by zz and only the first page
of HTML from zz ..."): I should need a configuration file which is easy
to edit, for specifying such criteria in sufficient detail. Then a perl
script will use various tools to do the decoding and printing,
considering the config. I'm expecting it to start somewhat simple and
getting more complicated over time when users figure out that they will
need a lot of criteria to keep the amount of paper wasted within
reasonable limits, so the config file format must be easily extendable
with further options.

Your ideas will be appreciated.


--
Knowledge is volatile and fluid. Software is power.

lee

unread,
Aug 30, 2014, 3:09:12 PM8/30/14
to begi...@perl.org
lee <l...@yun.yagibdah.de> writes:

> Hi,
>
> is there a module available to read configuration files which are like
> this:
>
>
> arbitrary_denominator-00 | alternate-denominator-00 | alternate-denominator-01 [| ...]
> {
> itemA = <some string>
> itemB = <some integer>
> itemC = <some float>
> itemD = <some CSV>
> }

Following-up my own question: I found [1] which appears to come close to
what I'm looking for. Of course, I'd still love to hear your ideas :)


[1]: https://metacpan.org/pod/Config::JSON

Richard Bailey

unread,
Aug 31, 2014, 1:06:29 AM8/31/14
to lee, begi...@perl.org

There is code available from my wizard at http://www.rtbaileyphd.com/perlwizard that is doing something fairly similar to what you described.  Use PerlWizard to generate a simple test program, run it once, and then examine the contents of the pwiz subirectory, which is where the config files go.  These are used in conjunction with Getopt::Long as well.

 

Best Regards,

R. T. Bailey

--

To unsubscribe, e-mail: beginners-...@perl.org For additional commands, e-mail: beginne...@perl.org http://learn.perl.org/

 

lee

unread,
Sep 7, 2014, 10:31:25 AM9/7/14
to begi...@perl.org
"Richard Bailey" <r...@rtbaileyphd.com> writes:

> There is code available from my wizard at
> http://www.rtbaileyphd.com/perlwizard that is doing something fairly similar
> to what you described. Use PerlWizard to generate a simple test program,
> run it once, and then examine the contents of the pwiz subirectory, which is
> where the config files go. These are used in conjunction with Getopt::Long
> as well.

Thank you very much for you input! I looked at the web page, and it
seems that the perlwizard is written in java, which is something I stay
away from as much as possible ...

I ended up with a pretty simple config file like this:


sender : subject : action1, action2, ..., actionN


From there, I've turned it into an emacs org-mode table for easier
editing. The script needs less than 100 lines to read it, including all
checks.

I really like those tables :)
0 new messages