in reply to Re^5: number array with space
in thread number array with space

hey

what i want to do is that check whether the array cell has a number or not , if yes execute my block of code else not i.e.

if( $array[$i] == number ) { my block of code ; }

Replies are listed 'Best First'.
Re^7: number array with space
by gurpreetsingh13 (Scribe) on Jun 20, 2013 at 09:42 UTC
    Simply go for regex then:
    if ($array[$i] =~ /\d+/){ <your code> }
      if ($array[$i] =~ /\d+/){ <your code> }

      But that matches non-numbers:

      >perl -wMstrict -le "print 'this is a number?!?' if 'x9x' =~ /\d+/; " this is a number?!?

      Better to use  Scalar::Util::looks_like_number() (see this), which correctly identifies numbers like  '1.2' '1.2e3' '0e0', or if only decimal digits are acceptable, use the  /^\d+$/ regex (see this).

        sorry..
        if $array[$i] =~ /^\d+$/ { <block of code> }