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
In reply to Regex to find the number of positive, negative, and 0 integers within a data set by neveraloneneverapart
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |