How to tell apart numeric scalars and string scalars in Perl?

前端 未结 9 1446
一生所求
一生所求 2020-12-16 12:31

Perl usually converts numeric to string values and vice versa transparently. Yet there must be something which allows e.g. Data::Dumper to discriminate between

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 13:08

    One simple solution that wasn't mentioned was Scalar::Util's looks_like_number. Scalar::Util is a core module since 5.7.3 and looks_like_number uses the perlapi to determine if the scalar is numeric.

提交回复
热议问题