Do note the use of chomp. It's much better than those regexps of yours.

Well, no. The OP did mention that the input data comes from a variety of OS's (though he didn't say which OS(s) his script is supposed to run on). Chomp will remove anything at the end of a record that matches "$/", whose default value is OS-dependent, which means that a when a script runs on any sort of unix, chomp will leave a "\r" untouched when the input happens to come directly from a CRLF source.

I would just recommend simplifying the OP's regex:

s/[\r\n]*$//;
Also, I'd recommend a while loop instead of  foreach my $line ( <DATA> ), because the for loop causes the entire file to be slurped into a list before the first iteration begins. For small files, that's not a problem, but why invite this sort of trouble if the files happen to get really big?

In reply to Re^2: Generating Hashes from arrays of arbitrary size by graff
in thread Generating Hashes from arrays of arbitrary size 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.