in reply to Check input sub - comments please...

I don't see anything wrong with the code, but the usage comments should explicitly mention what characters you are allowing. Also, you have a fairly restricted notion of numeric (i.e. no negatives, floating-point). "$numeric" may not be the right name.

Pet peeve: $ should not be used in regexs unless you really want to allow a trailing "\n"; probably not the case here.

  • Comment on Re: Check input sub - comments please...

Replies are listed 'Best First'.
Re: Re: Check input sub - comments please...
by shenme (Priest) on Dec 14, 2003 at 17:49 UTC
    Could you explain your pet peeve further?   I'm not sure what you are thinking about.
      $s = "8b\n";
      printf "  %smatch\n", ($s=~/^\d*$/) ? '' : 'no ';
        no match
      printf "  %smatch\n", ($s=~/^\d*/)  ? '' : 'no ';
        match
    
    Without the '$' the checking is, um, untrustworthy.
      Use \z to match the end of the string.
Re: Re: Check input sub - comments please...
by graff (Chancellor) on Dec 15, 2003 at 04:37 UTC
    $ should not be used in regexs unless you really want to allow a trailing "\n"; probably not the case here.

    Well, since all whitespace has been normalized to single space (and leading and trailing whitespace has been removed), $ works as well as anything else here.

      On the contrary, since it is impossible for there to be a trailing \n here, using $ instead of \z is misleading and wrong. It's just as incorrect as needlessly ending an unanchored regex with .*.