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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |