I have the following text file:
STORE MONITORING REPORT as of 13-05-02 10:05:07 Scanning for FTFIMS STORE002 -rwxr-xr-- 1 admins store 59025 Apr 11 2012 eft100.cbr 16295 58 -rwxr-xr-- 1 admins store 61143 Nov 15 15:47 chk075.cbr 33334 60 -rwxr-xr-- 1 admins store 420952 Sep 6 2012 test-encrypt 63327 412 -rwxr-xr-- 1 admins store 427068 Sep 6 2012 eft115-20 36184 418 -rwxr-xr-- 1 admins store 460694 Apr 3 06:15 eft6un 07640 450 -rwxrwxrwx 1 admins store 481069 Oct 4 2012 hostsocgw 46087 470 -rwxrwxrwx 1 admins store 503666 Feb 13 09:10 stratgw 22452 492 -rwxr-xr-- 1 admins store 14318 Nov 1 2010 unityrep 50196 14 STORE006 -rwxr-xr-- 1 admins store 59025 Apr 11 2012 eft100.cbr 16295 58 -rwxr-xr-- 1 admins store 61143 Nov 15 15:47 chk075.cbr 33334 60 -rwxr-xr-- 1 admins store 420952 Sep 6 2012 test-encrypt 63327 412 -rwxr-xr-- 1 admins store 427068 Sep 6 2012 eft115-20 36184 418 -rwxr-xr-- 1 admins store 460694 Apr 3 06:15 eft6un 07640 450 -rwxrwxrwx 1 admins store 481069 Oct 4 2012 hostsocgw 46087 470 -rwxrwxrwx 1 admins store 503666 Feb 13 09:10 stratgw 22452 492 -rwxr-xr-- 1 admins store 14318 Nov 1 2010 unityrep 50196 14
What I would like to do is save the first two lines off to a file then proceed to break down the rest as records. Right now my code merely is trying to break them into records, and it looks like:
my ($TEXTIN,$HTMLOUT); my $input2 = $outputfile; my $output2 = "FTFIMS.html"; my @records=(); my $inrecord=0; my $rxRecStart = qr{STORE\d+}; my $rxRecStop = qr{\n\s}; my $recordStr = q{}; open $TEXTIN,"<",$input2 || die "Can not open $input2: $!\n"; open $HTMLOUT,">",$output2 || die "Can not open $output2: $!\n"; print $HTMLOUT "<html>\n<body>\n<pre>"; while(<$TEXTIN>){ if (m{$rxRecStart}){ $inrecord = 1; push @records, $recordStr if $recordStr; $recordStr = $_; }elsif(m{$rxRecStop}){ $inrecord = 0; push @records, $recordStr if $recordStr; $recordStr = q{}; }else{ $recordStr .= $_ if $inrecord; } } close $TEXTIN; print $HTMLOUT "$records[0]"; print $HTMLOUT "$records[1]"; print $HTMLOUT "\n</pre>\n</body>\n</html>"; close $HTMLOUT;
Right now, the above code is only printing the contents of $records[0], which is the first one that starts with STORE002. $records[1] is empty, which means my regular expressions for the record start and record stop are incorrect.
As always, give me a pointer in the right direction. Thanks.

TStanley
--------
People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

In reply to Splitting a file into records by TStanley

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.