Perhaps something like this is what you want......
#!/usr/bin/perl -w use strict; my (%options,$curroption); while(<DATA>) { # read from __DATA__ filehandle below chomp; # get rid of trailing newlines next if /^\s*#/; # skip if it the first nonspace char is '#'. # set the curroption if the first item in the line is in all caps $curroption = $1 if s/^([A-Z]+) //; # make $currroption a hash key whose value is an array ref containin +g # the various options we found. push(@{$options{$curroption}},$_) for (split(/,\s*/)); } # print the datastructure which is a HoA (Hash of Arrays); for my $option (keys %options) { my @vals = @{$options{$option}}; print "$option -- ", join (',',@vals), "\n"; } __DATA__ # comment # comment ON Mon, Tues, Fri, Sat # comment other stuff
Output:
ON -- Mon,Tues,Fri,Sat,other stuff

-Blake


In reply to Re: How do you read the next line in a file while in a loop? by blakem
in thread How do you read the next line in a file while in a loop? by GroundZero

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.