neveraloneneverapart has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to come up with a set of regular expressions that can go into the code I have written to scan the data at the end of the code and tell me how many positive, negative, and 0 integers.
#!/usr/bin/perl use strict; use warnings; my ( $ctrP, $ctrN, $ctrZ ) = ( 0, 0, 0 ); while( my $num = <DATA> ) { chomp($num); ## print "num=[$num]\n"; if ( $num =~ /REGEX FOR POSITIVE/ ) { $ctrP++; } elsif ( $num =~ /REGEX FOR NEGATIVE/ ) { $ctrN++; } else { $ctrZ++; } } 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__ 29 -62 696 242 78 -564 0 45 855 22 -67
Content above restored by GrandFather
Solved
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex to find the number of positive, negative, and 0 integers within a data set
by BrowserUk (Patriarch) on Feb 28, 2017 at 20:46 UTC | |
|
Re: Regex to find the number of positive, negative, and 0 integers within a data set
by 1nickt (Canon) on Feb 28, 2017 at 17:48 UTC | |
by neveraloneneverapart (Initiate) on Feb 28, 2017 at 17:55 UTC | |
by stevieb (Canon) on Feb 28, 2017 at 17:59 UTC |