作者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