throop has asked for the wisdom of the Perl Monks concerning the following question:

Need help choosing which initialization module to use.

I have a large program which processes batches of text files (derived from MS-Word, .pdf, Excel etc.) For each batch, there's an initialization file. Right now, the details of each initialization get wrapped inside a function. This illustrates what I have currently:

sub RqtInitSABER{ my($Args) = @_; $runSwitches = {topArgs => { fileReadFn => \&eat_AvionicsFMEA, hiliteCol => [1,3,4,5], xtraTh => {1 => {colspan=>2, text=> ' '}, 3 => {colspan=>4, text=> 'Front'}}}, flamencoArgs => spec => # For what goes in the flamenco/specifications.py file +. {PAGE_TITLE => 'SABER Requirements', PAGE_HEADING => 'SABER Software Requirements Oct Release', }
I'm imagining I need something like:
[topArgs] fileReadFn= eatAvionicsFMEA hiliteCol= [1,3,4,5] [[xtraTh]] [[[1]]] colspan=2 text=' ' [[[3]]] colspan=4 text='Front' [flamencoArgs] [[spec]] PAGE_TITLE = SABER Requirements PAGE_HEADING = SABER Software Requirements Oct Release
I want to change this to a declarative .ini style. I've looked at Config::Simple and Config::IniFiles. But I can't figure out how to do a few things. I need to have:
I want to get away from having my config files be Perl code, but I'm not hard-over on using this style of .ini file. I just don't want to roll-my-own initialization code. Do some of the existing packages get me what I need?

Replies are listed 'Best First'.
Re: Finding the right initialization-file module
by GrandFather (Saint) on Dec 13, 2011 at 00:57 UTC

    YAML is what I would use for such a task. With a little OO help you can even do the "by name" function stuff:

    use strict; use warnings; use YAML; my $yamlStr = <<YAML; --- flamencoArgs: spec: PAGE_HEADING: SABER Software Requirements Oct Release PAGE_TITLE: SABER Requirements topArgs: fileReadFn: eat_AvionicsFMEA hiliteCol: - 1 - 3 - 4 - 5 xtraTh: 1: colspan: 2 text: ' ' 3: colspan: 4 text: Front YAML my $stuff = bless YAML::Load($yamlStr); my $fn = $stuff->can ($stuff->{topArgs}{fileReadFn}); $fn->() if $fn; sub eat_AvionicsFMEA { print "Hey, how about that!\n"; }

    Prints:

    Hey, how about that!
    True laziness is hard work
      Many thanks! That looks like just the ticket.

        Of course given that $stuff is an object we can squeeze a little more juice out:

        ... $stuff->header(); $fn->($stuff) if $fn; sub header { my ($self) = @_; print <<HEADER; $self->{flamencoArgs}{spec}{PAGE_HEADING} $self->{flamencoArgs}{spec}{PAGE_TITLE} HEADER } sub eat_AvionicsFMEA { my ($self) = @_; print "hiliteCols are: @{$self->{topArgs}{hiliteCol}}\n"; }

        Prints:

        SABER Software Requirements Oct Release SABER Requirements hiliteCols are: 1 3 4 5
        True laziness is hard work