Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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
Replies are listed 'Best First'.
Re: only numeric data
by tobyink (Abbot) on Jun 28, 2013 at 05:48 UTC

    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 arnaud99 (Beadle) on Jun 28, 2013 at 07:18 UTC


    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($_); }


    ~/perl/ex/perlmonks: perl 25.36 36.36 85.1

    I hope this helps


Re: only numeric data
by Anonymous Monk on Jun 28, 2013 at 07:08 UTC

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2015-10-06 23:48 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (164 votes), past polls