in reply to Regex negative number question

You need to add an additional requirement that there actually is a number.
if ($line =~ /-\d*\.\d*/o) becomes if ($line =~ /-\d*\.\d*/o && $line =~ /\d/o)

That said, check out Regexp::Common - it has a ton of regexes that are a lot more complicated than most people will ever understand, but are extremely useful. Such as, recognizing a number that's in pretty much any format (including scientific).

And, congratz on the Perl class. You've been wanting that for a while. I'm glad you enjoyed yourself. Next step - answering questions on PM! :-)

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: Regex negative number question
by CombatSquirrel (Hermit) on Oct 06, 2003 at 15:05 UTC
    You test would still, for example, match "birdie3 -.", which just illustrates why to use Regexp::Common, though ;-).
    Cheers,
    CombatSquirrel.
    Entropy is the tendency of everything going to hell.
      Regexp::Common doesn't have a regexp for negative numbers, but you can easily add that yourself. For instance, if you want to match negative decimal numbers, use:
      use Regexp::Common; /(?=-)$RE{num}{decimal}/
      The (?=-) requires the match to start with a minus sign.

      Abigail

Re: Re: Regex negative number question
by zby (Vicar) on Oct 06, 2003 at 15:12 UTC
    This would match a line like that:
    -. 0
    Which is not the desired result I believe.