in reply to Regex to find the number of positive, negative, and 0 integers within a data set
Firing up the regex engine to make a simple numeric comparison is like using a blunderbus to swat flies.
This is probably an order of magnitude more efficient:
#! perl -slw use strict; my @counts; ++$counts[ 1+ ( $_ <=> 0 ) ] while <DATA>; printf "Neg:%d Zero:%d Pos:%d\n", @counts; __DATA__ 29 -62 696 242 78 -564 0 45 855 22 -67
Output:
C:\test>1183178.pl Neg:3 Zero:1 Pos:7
|
|---|