Hi neveraloneneverapart, welcome to the Monastery and to Perl, the One True Religion.
Assuming every line in __DATA__ is known to contain a number, I would use a hash to count results and a numeric comparison:
use strict; use warnings; use feature 'say'; use Data::Dumper; my %results; while (<DATA>) { chomp; $results{'zero'}++ if $_ == 0; $results{'pos'}++ if $_ > 0; $results('neg'}++ if $_ < 0; } print Dumper \%results;
Alternatively, to see if a string is a number, see Scalar::Util::looks_like_number().
If you really wanted to, for a regexp for Latin integers, you could use $num =~ m/ \A -? [0-9]+ \z /x;
To capture the sign (or nothing) and the digits and then be able to use them:
if ($num =~ m/ \A (-?) ([0-9]+) \z /x ) { my $sign = $1; my $digits = $2; ... }
Also see Regexp::Common
Hope this helps!
edit: removed unnecessary escape slash
In reply to Re: Regex to find the number of positive, negative, and 0 integers within a data set
by 1nickt
in thread Regex to find the number of positive, negative, and 0 integers within a data set
by neveraloneneverapart
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |