5 ms·
> Perl doesn't have a way to say "this value is a number" or "this value is a string". use Scalar::Util qw(looks_like_number); #example if(looks_like_number(
by heresie-dabord 5y ago
> Perl doesn't have a way to say "this value is a number" or "this value is a string".
use Scalar::Util qw(looks_like_number);
#example
if(looks_like_number($value)) { say "$value is a number"; }
- a1369209993 5y agomy @chips = ("74HC08","8085AH","555","7C199-15"); use_value($_) foreach @chips; 555 is a number; "555" is not a number.
- jwilk 5y agoBut looks_like_number("42") is still true. OTOH, JSON::PP can tell the difference between string and number: $ perl -MJSON::PP -E 'say JSON::PP::encode_json(42);' 42 $ perl -MJSON::PP -E 'say JSON::PP::encode_json("42");' "42"
- heresie-dabord 5y agoIsn't it that this is specifically JSON syntax? "JSON recognises JSON".
- jwilk 5y agoNo.