Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

only numeric data

by Anonymous Monk
on Jun 28, 2013 at 05:46 UTC ( #1041140=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hey i have data which looks like @data=("conteent" , , , ,25.36,36.36,85.1,.....) . So i want a if statement whose block is accessed only when numeric part comes. Point to be noted is all have decimal points . I did this

if ($data[$i] =~ /^[0-9]+$/) { }

but still its not working , maybe because of decimal point . need help

Comment on only numeric data
Download Code
Re: only numeric data
by tobyink (Abbot) on Jun 28, 2013 at 05:48 UTC
    /^[0-9.]+$/

    Though it depends on what you count as numeric. What about "1.2.3"? What about "infinity"?

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

      hey this is a surety that numeric data will be some finite numbers with decimal like 25.1 , 998.1 , 55.1 ,56.9

Re: only numeric data
by Anonymous Monk on Jun 28, 2013 at 07:08 UTC
Re: only numeric data
by arnaud99 (Beadle) on Jun 28, 2013 at 07:18 UTC

    Hi

    Would using looks_like_number() help?

    use Modern::Perl; use Scalar::Util qw /looks_like_number/; my @data=("conteent" , , , ,25.36,36.36,85.1,'xx','.....'); for (@data) { say $_ if looks_like_number($_); }

    Output

    ~/perl/ex/perlmonks: perl check_numbers.pl 25.36 36.36 85.1

    I hope this helps

    Arnaud

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1041140]
Approved by frozenwithjoy
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2014-07-14 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (259 votes), past polls