I've been working on a script in the past couple of days thats news boxes of other site. I've put the script in my stratchpad. So now I'm trying to improve the code and make it less spaghetti like. First of all I'd like to improve the config file parsing. I've been trying to redo it and so far I have
my $sites_conf = "$ENV{'HOME'}/.newsboxes/sites.conf"; my %sites_config = parse_sites_config(); sub parse_sites_config { open SITES_CFG, "< $sites_conf" or die "Couldn't open $sites_conf: + $!\n"; my %options; while(<SITES_CFG>) { chomp; s/\/\/\s+.*//g; # Get rid of comments; next unless length; if (my($key, $operator, $value) = /^\s*?(\S+)\s*?(\=\>?)\s*?(\S+)\ +s*$/) { if ($operator eq "=>") { ++$options{'total_sites'}; $options{$options{'total_sites'}}{'site_name'} = $key; $options{$options{'total_sites'}}{'site_url'} = $value; } elsif ($operator eq "=") { $options{$options{'total_sites'}}{$key} = $value; } else { die "Ooops you might want to check $sites_conf for errors for +site: $options{$options{'total_sites'}}{'site_name'}\n"; } } } return %options; }
Also the sites entry in the config file usually looks like this
Kuro5hin => http://www.kuro5hin.org key = k5 story_tag = item title_tag = title link_tag = link site_xml = http://www.kuro5hin.org/backend.rdf refresh = 1800 colour_1 = #302BA2 colour_2 = #FFFFFF colour_3 = #E0E0E0 colour_4 = #302BA2
But sometimes such as for "Linux Today" it has the space in the site name and because I'm using \S+ to match that it's not working for those sites that have space(s) in their names. So I was wondering what I should be using instead. Thanks.

In reply to A little config parsing. by rendler

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.