【问题标题】:Perl convert string to numeric number [closed]Perl将字符串转换为数字[关闭]
【发布时间】:2017-02-28 07:57:09
【问题描述】:

我想在 perl 中将字符串序数转换为数字 我已经搜索过,但没有得到确切的答案。

例子:如果输入是

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

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

【问题讨论】:

    标签: perl perl-module


    【解决方案1】:

    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");
    

    【讨论】:

    • 非常感谢 Dave,它工作正常。
    • 我想知道“十九”是否真的有效!
    • 150 亿、600 万和 19 个 15006000019
    • @Borodin - 我的答案的原始版本包括一条评论,他可能需要修复“hundared”的拼写才能起作用。然后我在文档中看到“可以理解各种数字的拼写错误。”
    猜你喜欢
    • 2013-09-17
    • 2021-05-24
    • 2021-05-01
    • 1970-01-01
    • 2018-05-02
    • 2014-03-15
    • 2011-06-14
    • 2012-03-17
    相关资源
    最近更新 更多