Is it possible that some blank lines exist, or header or footer lines that don't have all the fields?

That happens pretty often in files I deal with. In that case, you have 2 options.

If none of the header/footer/blank lines have all the fields, you can just do

if(@array>14) { print STDOUT "$array[13]\t$array[14]\n"; print OUTFILE .... }
(assuming you open OUTFILE above the loop, and want to write all these items to it, as someone else suggested...)

If you have a "header" type line, or line of dividers or something like that, then you'll have to add some checks to skip this, like:

while(<FILEHANDLE>) { next if /------/; # skip divider line next if /SALES/; # skip header line next if /TOTAL/; # skip summary line next if /^$/; # skip blank lines ... }
with the correct regular expressions for your data, of course. Make sure that SALES can never appear on a normal line, for instance, if you're going to use that as a screen.

Hope this helps!
--
Mike


In reply to Filter for the lines where your data is... by RMGir
in thread hashes of arrays ?? by lolly

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.