作者frank1983 (What?)
看板Perl
标题Re: [问题] 判断数字与否
时间Tue Jan 19 00:05:13 2010
※ 引述《heliosy (这一栏是要做啥用的)》之铭言:
: 请问一下
: Perl中有没有function可以判断这个变数是否为数字呢?
: 例如:isNumeric() 或 isNumber()
: 之类的
: 谢谢
如果你不想自己写 regex
或是你想比对的数字非常复杂
也许你可以使用官方套件 Scalar::Util 所提供的 looks_like_number()
use Scalar::Util qw(looks_like_number);
或是安装 Regexp::Common,使用它所提供的 number regex
use Regexp::Common qw(number);
相关说明请参考:
1.
http://perldoc.perl.org/Scalar/Util.html
2.
http://search.cpan.org/dist/Regexp-Common/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.230.178.185
1F:推 heliosy:谢谢 :) 02/05 00:51