Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-12-27 01:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls