To answer the question you asked by /msg, try the following:
while (my $line = <MYFILE>) { chomp $line; # Do stuff here }

The problem is that $line was a global variable. strict complains about that, so you have to my the variable when you use it. The above is (almost) the standard way of handling a file line by line. The standard way most people do it would be to use $_ as much as possible. Something along the lines of:

while (<MYFILE>) { # Skip commented-out lines (or whatever else you want to do) next if /^#/; # Don't chomp unless we know we're going to use the line chomp; if (/SOME REGEX HERE/) { # Do stuff } }

Now, you don't want to chomp in the while condition. If you have a last line without a newline, that line will be skipped because chomp will indicate that it wasn't able to remove anything by returning undef.

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re: Regex negative number question by dragonchild
in thread Regex negative number question by Lori713

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.