Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-06-18 08:52 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.