Skip to content

Instantly share code, notes, and snippets.

@bessarabov
Created March 7, 2024 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bessarabov/c12a062692f78a0307e369e928e07b74 to your computer and use it in GitHub Desktop.
Save bessarabov/c12a062692f78a0307e369e928e07b74 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use feature qw(say);
use constant MY_CONSTANT => "42";
use Cpanel::JSON::XS;
say encode_json { value => MY_CONSTANT };
my $smth = 0 + MY_CONSTANT;
@bessarabov
Copy link
Author

This output

{"value":42}

But I would like to see in the output json the same type of the variable that I've used when defining constant, so in this case I expect to see

{"value":"42"}

https://stackoverflow.com/questions/78124050/how-to-make-perl-number-constant-to-be-always-a-number-when-serializing-to-json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment