2017-02-28 129 views
0

我想将字符串序号转换为perl中的数字 我已搜索但未得到确切答案。Perl将字符串转换为数字号码

例如:如果输入的是

one it should be 1. 
five hundred it should be 500. 
three hundred it should be 300. 

是否有任何模块做到这一点?

回答

6

一个Perl的最好的部分是CPAN,果然,在metacpan戳左右一对夫妇分钟后变成了Lingua::EN::Words2Nums模块:

use Lingua::EN::Words2Nums; 
$num=words2nums("two thousand and one"); 
$num=words2nums("twenty-second"); 
$num=words2nums("15 billion, 6 million, and ninteen"); 
+0

非常感谢戴夫,它工作正常。 – depsai

+0

不知“ninteen”是否真的有效! – Borodin

+0

150亿,600万和ninteen'15006000019' – ssr1012