When I test the code in windows, I get the results im looking for (https://imgur.com/a/59SKl). But when I test it on mac, I get different results (https://imgur.com/a/ZJMEg) in the positive and negative integers. Whats wrong with my regex?
#!/usr/bin/perl
# The program calculates the total zeros and positive intergers from t
+he data using regex
use strict;
use warnings;
my ( $ctrP, $ctrN, $ctrZ ) = ( 0, 0, 0 );
while( my $num = <DATA> ) {
chomp($num);
## print "num=[$num]\n";
if ( $num =~ /^[0].{0}/ ) {
$ctrZ++;
}
elsif ( $num =~ /^\d[0-9]{1,3}$/ ) {
$ctrP++;
}
else {
$ctrN++;
}
}
printf("freq(Z+):%8s\n", $ctrP );
printf("freq(Z-):%8s\n", $ctrN );
printf("freq(0):%9s\n", $ctrZ );
printf("Total:%11s\n", ($ctrP+$ctrN+$ctrZ) );
exit;
__DATA__
19
-22
498
512
15
-932
0
22
808
17
-32
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.