Data::Util::is_number()を実装すべく数値処理を調べていたらPerlの暗黒面を覗いてしまった。 Perlの数値処理ルーチンは,Perl Parserが行うリテラルの処理と,Perl_grok_*を中心とした数値変換ルーチンが行う処理がある。この記事では便宜的に,前者で処理できることをparsability*1,後者で処理できることをgrokability*2と呼ぶ。 ある値が数値か否かを調べるにあたって問題になるのは,parsabilityとgrokabilityの処理範囲が異なるという点である。 parsabilityはeval()で,grokabilityはScalar::Util::looks_like_number()で調べることができる。 #!perl -w use strict; use Data::Util qw(neat); use Scalar::Ut