While certainly not shorter than other posts, I believe the following provides what the OP is looking for.


#!c:\perl\bin\perl.exe use strict; use warnings; my @comments; my $i; my $j = 0; my $found_comment = 0; my $input = 'c:\yourdirectoryhere\sample_perl_data1.txt'; my $line; open(IN, $input) or die("Can't open file - $input: $!"); while($line = <IN>) { if($line =~ m/^=/) { if($line =~ m/^===Comments===/) { $found_comment = 1; if(! defined $i) { $i = 0; } else { $i++; } $comments[$i] = ""; # initialize new comments array el +ements } else { $found_comment = 0; } } else { if($found_comment == 1) { $comments[$i] = $comments[$i] . $line; } } } close(IN) or die("Unable to close file - $input: $!"); #print output with a separator line between each element for($j=0; $j<=$i; $j++) { print("comments[$j] = $comments[$j]"); print("------------separator-------------------\n"); }

Update:

Sample output below:

comments[0] = User comments are added here. A user may write whatever they may wish. ------------separator------------------- comments[1] = Comments are related to the microarray data here. ------------separator------------------- comments[2] = Comments related to the pathway information here. ------------separator-------------------

In reply to Re: Regular Expressions Challenge by dineed
in thread Regular Expressions Challenge by danj35

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.