When does the difference between a string and a number matter in Perl 5?

后端 未结 4 1737
逝去的感伤
逝去的感伤 2020-12-17 19:30

If a string in Perl 5 passes looks_like_number, it might as well be a number. For instance,

my $s = \"10\" + 5;

results in $s

4条回答
  •  既然无缘
    2020-12-17 20:20

      DB<1> sub is_num { my $x = shift; "$x " ~~ $x }
    
      DB<2> print is_num(123)
    1
      DB<3> print is_num('123')
    
      DB<4> 
    

提交回复
热议问题