In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/e80576f865224b380520be1bf5299811acc93967?hp=88ca7d892c9ed151d5d1259893141d1e90a72f24>
- Log ----------------------------------------------------------------- commit e80576f865224b380520be1bf5299811acc93967 Author: brian d foy <brian.d....@gmail.com> Date: Mon Sep 27 10:45:19 2010 -0500 * Don't allow extra newlines in number type example in perlfaq4 + How do I determine whether a scalar is a number/whole/integer/float? ----------------------------------------------------------------------- Summary of changes: pod/perlfaq4.pod | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index bc5c073..5a8c8a2 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -2509,13 +2509,13 @@ some gotchas. See the section on Regular Expressions. Assuming that you don't care about IEEE notations like "NaN" or "Infinity", you probably just want to use a regular expression. - if (/\D/) { print "has nondigits\n" } - if (/^\d+$/) { print "is a whole number\n" } - if (/^-?\d+$/) { print "is an integer\n" } - if (/^[+-]?\d+$/) { print "is a +/- integer\n" } - if (/^-?\d+\.?\d*$/) { print "is a real number\n" } - if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print "is a decimal number\n" } - if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) + if (/\D/) { print "has nondigits\n" } + if (/^\d+\z/) { print "is a whole number\n" } + if (/^-?\d+\z/) { print "is an integer\n" } + if (/^[+-]?\d+\z/) { print "is a +/- integer\n" } + if (/^-?\d+\.?\d*\z/) { print "is a real number\n" } + if (/^-?(?:\d+(?:\.\d*)?|\.\d+)\z/) { print "is a decimal number\n" } + if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?\z/) { print "a C float\n" } There are also some commonly used modules for the task. -- Perl5 Master Repository