Subject: | Suggestion for new function: _CFLOAT |
I'd like to suggest a new function _CFLOAT which works much like _POSINT
but checks whether the scalar is a valid C float. You can use the regex
that is given in the FAQ at "perldoc -q float".
Diff attached
Subject: | diff.txt |
--- Util.pm.old 2006-01-30 16:59:13.000000000 +0100
+++ Util.pm 2006-01-30 17:20:20.000000000 +0100
@@ -65,7 +65,7 @@
@EXPORT_OK = qw{
_STRING _IDENTIFIER _CLASS
- _POSINT
+ _POSINT _CFLOAT
_SCALAR _SCALAR0
_ARRAY _ARRAY0
_HASH _HASH0
@@ -169,6 +169,29 @@
=pod
+=head2 _CFLOAT $float
+
+The C<_CFLOAT> function is intended to be imported into your
+package, and provides a convenient way to test to see if a value is
+a number in valid C floating point format. That is, it is defined
+and matches the following regular expression:
+
+ m/^[+-]?(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee][+-]?\d+)?$/
+
+Returns the value as a convience, or C<undef> if the value is not a
+C float.
+
+=cut
+
+sub _CFLOAT ($) {
+ ( defined $_[0] and not ref $_[0]
+ and $_[0] =~ m/^[+-]?(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee][+-]?\d+)?$/ )
+ ? $_[0]
+ : undef;
+}
+
+=pod
+
=head2 _SCALAR \$scalar
The C<_SCALAR> function is intended to be imported into your package,