If you are getting different results on the MAC vs Windows, a very likely culprit would be the line endings and what chomp does.

This isn't "perfect", but gives an idea. I would use better variable names so that you have a chance to understand them 5 years from now.

#!usr/bin/perl # The program calculates the total zeros and positive integers from # the data using regex use strict; use warnings; my ( $c_positive_int, $c_negative_int, $c_zero_int, $ctr_not_int) = ( +0, 0, 0, 0 ); while( my $num = <DATA> ) { $num =~ s/^\s+//; # delete leading space(s) $num =~ s/\s+$//; # delete trailing space(s) if ( $num =~ /^0$/ ) # integer single 0 { $c_zero_int++; } elsif ( $num =~ /^\d+$/ ) # only positive digits { $c_positive_int++; } elsif ( $num =~ /^-\d+$/ ) #leading minus sign, then only digi +ts { $c_negative_int++; } else { $ctr_not_int++; #non integer print "**** Error $num is not an integer!\n"; } } printf "freq(Z+):%8i\n", $c_positive_int; printf "freq(Z-):%8i\n", $c_negative_int; printf "freq(0): %8i\n", $c_zero_int; printf "freq(?): %8i\n", $ctr_not_int; printf "Total: %8i\n", $c_positive_int + $c_negative_int + $c_zero_int + $ctr_not_int ; =Results **** Error 32.5 is not an integer! freq(Z+): 7 freq(Z-): 3 freq(0): 1 freq(?): 1 Total: 12 =cut __DATA__ 19 -22 498 512 15 -932 0 22 808 17 -32 32.5

In reply to Re: Integer regex, different results in windows and mac - I just need regex help by Marshall
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.