Perl将字符串转换为数字

dep*_*sai 0 perl perl-module

我想将一个字符串序号转换为我搜索过的perl中的数字,但是没有得到确切的答案.

示例:如果输入是

one it should be 1.
five hundred it should be 500.
three hundred it should be 300.
Run Code Online (Sandbox Code Playgroud)

有没有任何模块可以做到这一点?

Dav*_*man 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");
Run Code Online (Sandbox Code Playgroud)