cvs commit: perlfaq perlfaq4.pod
[email protected] (Robert Spier) 20 Sep 2003 06:37:43 -0000
| Newsgroups | perl.cvs.perlfaq |
|---|---|
| Message-ID | <[email protected]> |
cvsuser 03/09/19 23:37:43 Modified: . perlfaq4.pod Log: From: Iain Truskett <[email protected]> To: [email protected] Subject: [PATCH perlfaq4] 'is a number?' updated Date: Sun, 14 Sep 2003 00:13:29 +1000 [1 <text/plain; us-ascii (7bit)>] Update to reflect the inclusion of Scalar::Util into core. Style note: I note the FAQ takes the correct approach and calls it 'the CPAN'. Contemporary usage has it as just 'CPAN'. I assume 'correct' is favoured over 'popular'? Revision Changes Path 1.49 +12 -8 perlfaq/perlfaq4.pod Index: perlfaq4.pod =================================================================== RCS file: /cvs/public/perlfaq/perlfaq4.pod,v retrieving revision 1.48 retrieving revision 1.49 diff -u -w -r1.48 -r1.49 --- perlfaq4.pod 20 Sep 2003 06:33:25 -0000 1.48 +++ perlfaq4.pod 20 Sep 2003 06:37:43 -0000 1.49 @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 1.48 $, $Date: 2003/09/20 06:33:25 $) +perlfaq4 - Data Manipulation ($Revision: 1.49 $, $Date: 2003/09/20 06:37:43 $) =head1 DESCRIPTION @@ -2008,13 +2008,17 @@ if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print "a C float\n" } -You can also use the L<Data::Types|Data::Types> module on -the CPAN, which exports functions that validate data types -using these and other regular expressions, or you can use -the C<Regexp::Common> module from CPAN which has regular -expressions to match various types of numbers. +There are also some commonly used modules for the task. +L<Scalar::Util> (distributed with 5.8) provides access to perl's +internal function C<looks_like_number> for determining +whether a variable looks like a number. L<Data::Types> +exports functions that validate data types using both the +above and other regular expressions. Thirdly, there is +C<Regexp::Common> which has regular expressions to match +various types of numbers. Those three modules are available +from the CPAN. -If you're on a POSIX system, Perl's supports the C<POSIX::strtod> +If you're on a POSIX system, Perl supports the C<POSIX::strtod> function. Its semantics are somewhat cumbersome, so here's a C<getnum> wrapper function for more convenient access. This function takes a string and returns the number it found, or C<undef> for input that @@ -2037,7 +2041,7 @@ sub is_numeric { defined getnum($_[0]) } -Or you could check out the L<String::Scanf|String::Scanf> module on the CPAN +Or you could check out the L<String::Scanf> module on the CPAN instead. The POSIX module (part of the standard Perl distribution) provides the C<strtod> and C<strtol> for converting strings to double and longs, respectively.