hiyesthanks has asked for the wisdom of the Perl Monks concerning the following question:
#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Integer regex, different results in windows and mac - I just need regex help
by kcott (Archbishop) on Oct 19, 2017 at 03:28 UTC | |
|
Re: Integer regex, different results in windows and mac - I just need regex help
by Marshall (Canon) on Oct 19, 2017 at 06:49 UTC | |
|
Re: Integer regex, different results in windows and mac - I just need regex help
by pryrt (Abbot) on Oct 19, 2017 at 13:44 UTC | |
|
Re: Integer regex, different results in windows and mac - I just need regex help
by dave_the_m (Monsignor) on Oct 19, 2017 at 06:45 UTC | |
|
Re: Integer regex, different results in windows and mac - I just need regex help
by haukex (Archbishop) on Oct 19, 2017 at 08:16 UTC | |
|
Re: Integer regex, different results in windows and mac - I just need regex help
by choroba (Cardinal) on Oct 19, 2017 at 21:06 UTC |