Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to determine if something is numeric?

by Anonymous Monk
on Jan 30, 2004 at 19:44 UTC ( #325364=note: print w/replies, xml ) Need Help??


in reply to How to determine if something is numeric?

#!/usr/bin/perl -w use strict; my @numbers = ('-1', 1, 1000, '0001', 'abc', 34, '0x65', "1.2", '3.', '.3'); sub is_numeric { return $_[0] =~ /^[1-9][0-9.]*$/ } for (@numbers) { if (is_numeric($_) ){ print "$_ is numeric\n"; } else { print "$_ is NOT numeric\n"; } } __END__ -1 is NOT numeric 1 is numeric 1000 is numeric 0001 is NOT numeric abc is NOT numeric 34 is numeric 0x65 is NOT numeric 1.2 is numeric 3. is numeric .3 is NOT numeric

Replies are listed 'Best First'.
Re: Re: How to determine if something is numeric?
by antirice (Priest) on Jan 30, 2004 at 21:08 UTC

    Try this @numbers:

    my @numbers = qw(0.001 1.001 192.168.0.1);

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2021-04-16 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?