in reply to [SOLVED] How do I determine with a regular expression whether a scalar is a number/whole/integer/float?

Don't reinvent the weel, but have a look at Regexp::Common and Regexp::Common::number which has regular expressions for integers (both signed and unsigned and different bases), reals (or floating numbers in signed or unsigned format in different bases and even in "scientific notation"), decimal, octal and hexadecimal numbers and Roman numbers.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics
  • Comment on Re: How do I determine with a regular expression whether a scalar is a number/whole/integer/float?

Replies are listed 'Best First'.
Re^2: How do I determine with a regular expression whether a scalar is a number/whole/integer/float?
by thanos1983 (Parson) on Jul 12, 2015 at 13:46 UTC

    Hello CountZero,

    I was trying to avoid using modules, but maybe at the end I will. Thanks for pointing out some more options.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      Why would you try to avoid using modules? It is one of the major strengths of Perl, envied by many other languages.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

        Hello again CountZero,

        You are absolutely right about that. The only reason that I am trying to avoid using modules, is because I am building my own module. And I am trying to force the user to install as less as possible modules in order to use it. I am trying to use the pre installed modules of Perl.

        But other than that reason I agree with you 100%.

        Seeking for Perl wisdom...on the process of learning...not there...yet!