Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^7: number array with space

by gurpreetsingh13 (Scribe)
on Jun 20, 2013 at 09:42 UTC ( #1039928=note: print w/ replies, xml ) Need Help??


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

Simply go for regex then:

if ($array[$i] =~ /\d+/){ <your code> }


Comment on Re^7: number array with space
Download Code
Re^8: number array with space
by AnomalousMonk (Abbot) on Jun 20, 2013 at 13:08 UTC
    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
Node Status?
node history
Node Type: note [id://1039928]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2015-07-07 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls