Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^6: number array with space

by MynameisAchint (Novice)
on Jun 20, 2013 at 07:59 UTC ( [id://1039913]=note: print w/replies, xml ) Need Help??


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> }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1039913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found