Re: [問題] 判斷數字與否
※ 引述《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
推
02/05 00:51, , 1F
02/05 00:51, 1F
討論串 (同標題文章)
Perl 近期熱門文章
PTT數位生活區 即時熱門文章