http://www.perlmonks.org?node_id=715307

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

In a recent post, I asked if it was possible to parse out sections of a simple Makefile, and I stumbled upon Config::General, which seems to do the trick perfectly...

Or so I thought.

I found an edge condition that seems to be cropping up more and more in the Makefile targets I'm preprocessing, that breaks the standard parsing behavior of this module.

Further reading of the pod indicates that this module allows me to subclass the split operations, using -SplitPolicy and -SplitDelimiter. I've tried various incantations, but I can't seem to find the right magical mojo to make it do what I need.

So I'm here, asking if there are any other monks (or modules) that might be able to help me here. Here's some code that exhibits the problem:

# This is my sample config file TEMPLATE_FOO = 1 TEMPLATE_BAR = two OPTION_THREE = baz THIS_BREAKS = \ MULTILINE = \ Foo \ Bar \ Baz

And the perl that processes this:

use strict; use warnings; use Data::Dump qw(dump ddx); use Config::General; my $conf = Config::General->new(-ConfigFile => "sample.conf"); my %prev_config = $conf->getall; print dump(\%prev_config);

When I process this using the code above, I get the following result:

{ OPTION_THREE => "baz", TEMPLATE_BAR => "two", TEMPLATE_FOO => 1, THIS_BREAKS => "MULTILINE\t= Foo\tBar\tBaz", }

Note how THIS_BREAKS sucks the next lines up into its value container? That shouldn't happen, especially with the additional line break after the multi-line continuation.

I tried using -SplitDelimiter to compensate for this with some basic and complex regular expressions, without much success.

I looked into Config::General::Extended and it seems to have a bit more granular control over the hash keys and values, but I'd rather not do that kind of autopsy on the module's classes if I don't have to.

Is there another way to do this? Thanks in advance, my fellow brethren.

Replies are listed 'Best First'.
Re: An odd Config::General parsing problem
by GrandFather (Saint) on Oct 04, 2008 at 03:53 UTC

    There is a chop instead of a chomp in the module which screws up continuations for configuration files using Windows line ends (CRLF). I'll raise a bug report for it in a while - gtg now.

    Update: Raised ticked rt://39814.


    Perl reduces RSI - it saves typing