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'

In reply to Re^2: Int becomes String when I convert to json by Don Coyote
in thread Int becomes String when I convert to json by bartender1382

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.