Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: A function to determine if a string is numeric

by jwkrahn (Monsignor)
on Feb 24, 2012 at 03:39 UTC ( #955861=note: print w/ replies, xml ) Need Help??


in reply to Re: A function to determine if a string is numeric
in thread A function to determine if a string is numeric

$ perl -E' print "Enter a number or string: "; my $s = <STDIN>; chomp $s; if ( $s =~ /^[0-9,.E]+$/ ) { say "$s is a number\n"; } else { say "$s may be a string\n"; } ' Enter a number or string: ,,, ,,, is a number $ perl -E' print "Enter a number or string: "; my $s = <STDIN>; chomp $s; if ( $s =~ /^[0-9,.E]+$/ ) { say "$s is a number\n"; } else { say "$s may be a string\n"; } ' Enter a number or string: EEE EEE is a number $ perl -E' print "Enter a number or string: "; my $s = <STDIN>; chomp $s; if ( $s =~ /^[0-9,.E]+$/ ) { say "$s is a number\n"; } else { say "$s may be a string\n"; } ' Enter a number or string: -777 -777 may be a string

If you are going to use a regular expression then you should probably read the FAQ: How do I determine whether a scalar is a number/whole/integer/float?


Comment on Re^2: A function to determine if a string is numeric
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-21 03:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls