How do I tell if a variable has a numeric value in Perl?

前端 未结 14 1462
别那么骄傲
别那么骄傲 2020-11-28 06:56

Is there a simple way in Perl that will allow me to determine if a given variable is numeric? Something along the lines of:

if (is_number($x))
{ ... }
         


        
14条回答
  •  悲哀的现实
    2020-11-28 07:14

    A simple (and maybe simplistic) answer to the question is the content of $x numeric is the following:

    if ($x  eq  $x+0) { .... }
    

    It does a textual comparison of the original $x with the $x converted to a numeric value.

提交回复
热议问题