Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to An odd Config::General parsing problem by hacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-26 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found