In Perl, how can I tell if a string is a number?

后端 未结 7 959
青春惊慌失措
青春惊慌失措 2021-02-14 22:33

I am using Perl to convert some XML to JSON. If the XML attribute is a number, I don\'t want to put quotes around it so that JSON will treat it as a number and not a string. How

7条回答
  •  北恋
    北恋 (楼主)
    2021-02-14 22:46

    I think this question from perlfaq solves your problem.

    Generally the problem is defining what exactly you want to read as number.

    • is "-1.312" valid number?
    • is "inf"?
    • 5.34123412E-03 ?

提交回复
热议问题