I was going to reply something similar when I read the original node. But then I started to wonder whether perhaps the OP was dealing with legacy code and a file that used Windows and Unix line terminators interspersed. For example:

data1\n data2\r\n data3\n ...etc
If this file were to be read in under Windows in a while loop, the first line would be
data1\ndata2\r\n
,no? (Can't check, I don't have access to a Windows machine.) In which case splitting on \n and then pushing the resulting array into another one ( as suggested by shenme above ) would make perfect sense (albeit a chomp would still be required). Or am I mistaken?

In reply to Re^2: foreach on array by tirwhan
in thread foreach on array by Anonymous Monk

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.