seems like an awful lot of work to me. i actually wrote one this morning (admittedly not a module, but i dont see it as being necessary!) thats pretty easy to use and fits comfortably on 5 lines. this is actually my first posting so i hope the code turns out okay.
# %settings = grok ( qq(filename), %settings ); sub grok { my $n = shift; open IN, $n; my @in = <IN>; close IN; my %input = shi +ft; my %hash_to_return; foreach my $setting (keys %input) { my ($p_name, $p) = /^([^\s=]+)\b(?:(?:\s*=\s*)|\s+)(.*)$/; if ($setting eq $p_name) { $hash_to_return{$p_name} = $p } else { next } } return %hash_to_return } # # grok, above, posted earlier, is broken. :) it was actually # an old version (old being > 12 hours in this case) # I had in the wrong directory. Sorry for any confusion. # unfortunately, this one isnt nearly as pretty. # sub grok2 { my $n = shift; if ($n) { open IN, $n or warn "BDU error" } else { warn "BDU error" ; return } @in = <IN>; close IN; my %input = shift; foreach my $item (@in) { my ($p_name, $p) = $item =~ /^([^\s=]+)\b(?:(?:\s*=\s*)|\s+)(.*)$/; foreach my $setting (keys %i +nput) { if ($setting eq $p_name) { $input{$setting} = $p } else { next } } + } return %hash_to_return } # note some checking for files/vars was added for chipmunk. # nyah. :p # de_grok ( qq(filename), %settings ); sub de_grok { my $n = shift; open OUT, $n; my %output = shift; foreach my $line (keys %output) { print OUT $line . ' ' . $output{ $line } } close OUT }
as i recall, this compiles okay with -w and strict turned on. config file looks like "config_item the rest of the line are the arguments to config_item." since some users are kinda dumb about config files i allowed for a "config_var = params" too. the way i use this is like so:
my %CONFIG = ( server_name => 'localhost', server_alias => 'opennap', server_ports => '4444 7777 8888', max_user_channels => '5', max_nick_length => '32', ); %CONFIG = grok ( qq(config), %CONFIG );
i use this code in several applications. all of these focus on my opennap server. i set up my administration client-bots to grok in their config files (several actually) and the server reads its configs when it starts up and writes them to the disk every so often in case it crashes. its extremely versatile in that you can use it for userdb's, channeldb's, mp3 playlists, and so on.

cheers,
deprecated
(server in question is located at macachu.yi.org if you wanna have a looksee at an opennap server being developed in perl)


In reply to Re: Yet Another Config File Parser Module by deprecated
in thread Yet Another Config File Parser Module by jynx

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.