Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Matching floats according to perlfaq4

by rbi (Monk)
on Sep 26, 2002 at 10:54 UTC ( [id://200847]=note: print w/replies, xml ) Need Help??


in reply to Matching floats according to perlfaq4

I use this routine that I slightly changed from one posted here long ago, I think by Vroom, that I cannot find now in the site. It seems to work on those tests.
#!/usr/bin/perl -wl use strict; my @nums = qw( 0e0 0 +0 -0 1. 0.14 .14 1.24e5 24e5 -24e-5 2.3. 2.3.4 1..2 ); for (@nums) { print "ok: ", $_ if is_a_number($_); } ############### sub is_a_number { ############### my $var = $_[0]; $var =~ s/^\s+//; $var =~ s/\s+$//; if ($var =~ /^([+-]?)(\d+\.|\.\d+|\d+)\d*([Ee]([+-]?\d+))?$/) { return(1) } else { return(0) } }
Regards, Roberto

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found