How about something like this:

my @regex = qw( Desription Data ); # regexen to match my %rhash = (); my $which = 0; # which regexp to look for while (<>) { /^$regex[$which]:/ && do { # found one of them if ($which == 0 ) { # if it was the first one .. # process Description and Data arrays (if any) process_arrays( @rhash{ @regex } ); # reinitialize by associating an anon array with each regex @rhash{ @regex } = ( [] ) x @regex; } $which = 0 if (++$which >= @regex); next; } push @{$rhash[$which]}, $_; } # Since the last Data block won't be terminated with a # Description line, need to cleanup here process_arrays( @rhash{ @regex } ); # ... sub process_arrays { my ( $arrayref1, $arrayref2 ) = @_; # return immediately if both arrays are empty return unless $arrayref1 && @$arrayref1 && $arrayref2 && @$arrayref2 +; # ... }

Update: Oops! my first version was plagued with Off-By-One bugs. This should work (untested).

dmm

You can give a man a fish and feed him for a day ...
Or, you can
teach him to fish and feed him for a lifetime

In reply to Re: How to read lines from a file which is.... by dmmiller2k
in thread How to read lines from a file which is.... by ginju75

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.