teamassociated:

Part of the difficulty appears to be that the file may have some lines you want to discard. Since the $. variable keeps track of the lines read and not the lines wanted, using the modulo operator on it is going to fail. However, the modulo operator idea is a *good* one, you just need to keep track of the lines you want to keep yourself:

my $cnt_keepers=0; while (my $ln = <$f>) { next if .... # Now we've got a line we want to keep ++$cnt_keepers; if ($cnt_keepers % 5 == 0) { ... every fifth line processing ... } ... }

Another way you could do it is to simply accumulate the lines you want, and when you have five, process the lot of 'em:

my @records; while (my $ln = <$f>) { next if ... push @records, $ln; if (@records==5) { print "A $records[0]\n"; print "B $records[1]\n"; print "C $records[2]\n"; print "D $records[3]\n"; print "E $records[4]\n"; print "F $records[5]\n"; @records = (); } }

It may be coincidence, but it seems like the first record of each group always has a 'Z' (?record type indicator?) around column 20. If it's not a coincidence, then another way to handle it would be to accumulate records until you find a line with a 'Z' marker, then process all the records you have, and then put the new record into the accumulator.

Update: Fixed a code tag.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: raw data formatting by roboticus
in thread raw data formatting by teamassociated

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.