three18ti:

If it's always that format, you don't need anything fancy. Just read the file, split each line into two chunks at the first colon, and package it all up into a hash. It should be something like this:

sub read_config_file { my $file_name = shift; open my $FH, '<', $file_name or die "Can't read $file_name: $!\n"; my $result = {}; while (my $line = <$FH>) { my ($key, $value) = split /:/, $line, 2; $value =~ s/\r?\n$//; $result->{$key} = $value; } return $result; } my $config_data = read_config_file('config_file_name.cfg'); print "Daily mission: ", $config_data->{'What are we doing today Brain +'}, "\n"; print "Location: ", $config->data{where}, "\n";

(Note: untested...)

Update: I actually like Marpa::R2 a good bit. I just did a project at work with it last month where I had to write a parser for a programming language. I found it to be pretty nice to use in that capacity. But it's overpowered, in my opinion, if you have simple tag:value pairs in a configuration file.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Parsing an Arbitrary "config" file (based on a "template"?) by roboticus
in thread Parsing an Arbitrary "config" file (based on a "template"?) by three18ti

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.