Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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
Replies are listed 'Oldest First'.

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 romping around the Monastery: (16)
As of 2015-07-07 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (91 votes), past polls