#!/bin/perl #+ # is_float -- check whether the argument is floating point number # # Purpose: # Check whether the arguments are valid flaoting point numbers # by doing a pattern match. # # Usage: # is_float [arg1 arg2 ... argN] # # Arguments: # arg1, etc: strings to be evaluated as possible numbers # # Output: # Each valid float is printed on STDOUT # # Restrictions # A leading "+" will invalidate the string; e.g., "+1.00" is not # considered a valid number. # # Exit values: # 0 = normal completion; all values are floats # 1 = non-floats detected # # Type: # Perl5 script # # Example: # 1) check whether a variable is a floating point value: # set a = 1.234 # is_float $a # echo $status ( returns 0 ==> good) #- # Modification history: # Date unknown RWG Original version # 2000-Jul-05 GDW Added documentation #----------------------------------------------------------------------- $status = 0; foreach $arg ( @ARGV ) { $_ = $arg ; if ( /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ) { print ; print "\n"} else { $status=1} } exit $status;