in reply to Re: Int becomes String when I convert to json
in thread Int becomes String when I convert to json
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
|
|---|