http://qs321.pair.com?node_id=325364


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