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

The way forward always starts with a minimal test.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.