Just to confirm what the others have said, if you save your file with CRLF line endings on a system that uses LF line endings (*NIX, including Mac OS X) and run it, it gives the wrong results. If you then put binmode DATA, ':crlf'; just before the loop, it works again. :crlf is the default on Windows, see open and binmode, and it causes the CRLF line endings to be converted to LF, so that chomp works properly. Without :crlf, what is happening is that $num contains a trailing CRLF, but chomp only removes the LF, leaving the strings looking like "19\r", which you can see yourself if you use Data::Dump or Data::Dumper with $Data::Dumper::Useqq=1; - see also the Basic debugging checklist. The best solution IMO is to convert the file to LF line endings, for example using fromdos from the Tofrodos package, and also many text editors support selecting the line endings in the "Save As" dialog.

Also, regarding your regexes, I just wanted to point out Regexp::Common::number, which you might find useful, and also that the regex /^[0].{0}/ looks a little suspicious: .{0} doesn't really do anything, and rewriting the regex as /^0/ shows that it will accept any string beginning with a 0, including stuff like "0 but true", is that really what you want?


In reply to Re: Integer regex, different results in windows and mac - I just need regex help by haukex
in thread Integer regex, different results in windows and mac - I just need regex help by hiyesthanks

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.