in reply to Int becomes String when I convert to json

Most likely, enum returns all values as strings.

If you want to try to convince Perl (and JSON) that the value should be treated more like a number, try adding a zero to it:

$out{returnvalue} = 0+SSSTAGE1;

... or simply do the conversion at the end:

$out{returnvalue} = 0+$out{returnvalue};

Replies are listed 'Best First'.
Re^2: Int becomes String when I convert to json
by Don Coyote (Hermit) on May 10, 2022 at 10:20 UTC
    Hello Corion,
    Most likely, enum returns all values as strings.

    Just to clarify how the index is returned.

    Default simple usage will provide the index as numeric, but the user can invoke string context in the usual manners. That is, the user should not need to convert to number using 0+$index unless they already messed with the context previously.

    enum provides two indexing modes ENUM and BITMASK,with optional mnemonic prefix. ENUM mode is an incremented natural number index $n = $index++ and BITMASK is a binary basis multiplier assigned increment $n = $index *= 2.

    Throughout the module any standard numerical contexts such as hex, oct, underscore_inclusive are converted into standard decimal format.

    The index for the user supplied list literal is then set in a similar fashion to a constant, by creating a package name withif prefix, that is a code ref to a null-prototyped subroutine.

     *{$'calling'pkg$pfx$name} = sub () { $n }

    The upshot being that the context supplied for assignment of the sub should determine whether the scalar is stringified or numeric.

    hth


    do { $Monastery::Level::nCoyote = 'Hermit'. 'yey!' } or eval '$nCoyote = 10'