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

Hello Laurent_R,

Well I assumed that as soon it will match the if condition it will break. and this is the reason that I should modify it.

Regarding the array, I do not want the array to contain strings I want the array to contain numbers. This is why I define it like this my @numbers = (1, 1.0, 123.1, 0.1);. I verified the syntax from the tutorial Arrays: A Tutorial/Reference.

Seeking for Perl wisdom...on the process of learning...not there...yet!
  • Comment on Re^2: How do I determine with a regular expression whether a scalar is a number/whole/integer/float?
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: How do I determine with a regular expression whether a scalar is a number/whole/integer/float?
by Laurent_R (Canon) on Jul 12, 2015 at 12:08 UTC
    Well I assumed that as soon it will match the if condition it will break. and this is the reason that I should modify it.
    I am not sure that I understand correctly what you are saying, and I am not sure that you understood what I was saying.

    The FAQ's original code had continue statements so that every condition is checked, even if a previous condition succeeded. So that the FAQ code, presented with 1.0 would report a non digit and then also report a real number. Your code does not do that.

    For your nested if ... elsif ... else statements to work properly, you need to reorder your conditions, for example: 1. check if it is a positive integer; 2. check for a negative integer; 3. check for a (positive or negative) float; 4. check for non-digits other than those we have accepted when checking for negative and floats.

    my @numbers = (1, 1.0, 123.1, 0.1);
    is certainly a good way of declaring an array of numbers, but I was only stressing that your use of qw/.../ was incorrect because of the commas.

      Hello again Laurent_R,

      You are right, I should not use if and else in the order that I had it before. I have updated my question/answer based on your answer it started to make more sense.

      Thanks again for your time and effort.

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