http://www.perlmonks.org?node_id=1201659


in reply to Integer regex, different results in windows and mac - I just need regex help

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?