in reply to classifying data

Well, you make use of Regexp::Common. For instance, by doing:
use Regexp::Common; $has_dollar_sign = $str =~ s/^([-+]?)\$/$1/; if ($str =~ /^$RE{num}{decimal}{-sep => ','}{-keep}$/) { $is_numeric = 1; $sign = $2; $has_decimal_point = $5 ? 1 : 0; $has_commas = $str =~ /,/ }
Or you could take its regex and modify it to have an optional leading dollar sign.

Abigail

Replies are listed 'Best First'.
Re: Re: classifying data
by Art_XIV (Hermit) on Jan 19, 2004 at 16:45 UTC

    This could help you get started:

    use warnings; use strict; while (<DATA>) { chomp; my $data = $_; print "$data: "; my $result = ($data =~ /^[+\-]?\$?[0-9.]+$/) ? "numeric" : "non-numeric"; print "$result\n"; } __DATA__ 1020 $10.21 -1023 +1.024 beer 10$25 -$102.6 A1027 1028$ $ $-1.029

    BTW, watch out for those asterisk opertors in your patters. You used \d*, and the '*' could legitimately match '', since it does match a digit zero or more times! That pesky asterisk operator can lead to 'zero-width' matches, which can drive you nuts when you are starting with regular expresssions.

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
      Your regexp will not match 900,000, but it will match .....

      Abigail

        Upon reflection, I think that your plan of using RegExp::Common is superior.

        Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"