Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^5: number array with space

by 2teez (Vicar)
on Jun 20, 2013 at 07:09 UTC ( [id://1039901]=note: print w/replies, xml ) Need Help??


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

See looks_like_number in Scalar::Util like thus:

use Scalar::Util qw(looks_like_number); for(qw(1 perl 25 monks)){ looks_like_number $_ ? print $_," is a Number",$/ : print $_," is not a Number",$/; }
Update:
Awooooshhhh! davido, beat me to it.....

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^6: number array with space
by davido (Cardinal) on Jun 20, 2013 at 07:28 UTC

    Yeah, but I left out the example, which you thoughtfully provided. ...or I left it as an exercise for the reader to figure out. ;)


    Dave

Re^6: number array with space
by MynameisAchint (Novice) on Jun 20, 2013 at 07:59 UTC
    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 ; }
      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).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2026-04-20 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.