in reply to Re: How to check if a scalar value is numeric or string?
in thread How to check if a scalar value is numeric or string?
sub _isNumeric { my ($value) = @_; no warnings; return 1 if ($value + 0) eq $value; return 0; } my $var = { 'key1' => '1', 'key2' => 1 }; print "Key1: It is a number\n" if _isNumeric( $var->{'key1'} ) ; print "Key2: It is a number\n" if _isNumeric( $var->{'key2'} ) ;
Key1: It is a number Key2: It is a number
|
---|