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

后端 未结 7 945
青春惊慌失措
青春惊慌失措 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:47

    It might be easier for you to just read the XML into a data structure in Perl and let Perl's JSON library figure it out for you. It already has checking for that, so unless your number is actually a string in the XML (e.g. it's got a space after it, etc) JSON->encode() will encode it as a JSON number.

提交回复
热议问题