It was Wednesday, February 26, 2003 when T. Murlidharan Nair took the soap box, saying: : I have a cgi that need to accept only numeric values. ie +ve or -ve : real numbers. : Is there a quick and easy way to check this. I was trying using a reg exp : if(/^[-0-9][\.0-9]*/) { : do something : } : : but this breaks when the number is say --75.4 It still accepts if it : has two - signs.
Here's a nice trick. Use the int() function. It's documented in perlfunc, a short to the documentation is 'perldoc -f int'. When passed a string, int() will return 0. When passed a number, it will return the integer version of that number. Armed with this knowledge, it's fair to assume that when passed an integer, the following expression will be true: $data == int( $data ); It will return false if a fraction or a string is passed, in '$data'. So, try this: if ( $_ == int( $_ ) ) { # do something... } Enjoy! Casey West -- I am a superhero. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]