in reply to Reg Ex exercise
Seems like fairly arbitrary specs for what is or isn't a number. Ah well. Don't expect this to work for scientific notation, complex numbers, or anything else that isn't explicitly tested here.
printf "%s is %sa number.\n", $_, /^-?\d+(?:\.\d+)?$/ ? '' : 'NOT ' for qw/4 -7 0.656 -67.35555 5. 56F .32 -.04/;
4 is a number. -7 is a number. 0.656 is a number. -67.35555 is a number. 5. is NOT a number. 56F is NOT a number. .32 is NOT a number. -.04 is NOT a number.
|
|---|