In trying to create a hash mapping stringified numbers to some values, I came across what seems to me to be a bug in the dwimmery of the => operator.

Having given it some thought, it's pretty clear that the problem is that the 09 is lexed and converted before the statement is parsed (hard to get around that, eh?). However, it still results in code that doesn't DWIM.

# perl -e "%a = ( 09 => 'a' )" Illegal octal digit '9' at -e line 1, at end of line

To me, that should map the string "09" (as forced by the => operator) to the string "a", while in fact perl tries to map 09 to octal, and then force string context.

I suppose I'm curious about this on a number of levels. First, is this something that I'll just have to live with? Second, is there even a practical solution? It would be hard to do syntatic analysis before tokenizing, but I still feel like => isn't behaving as expected.

Update: Before someone tells me to use an array, I have every intention for 01 to be a different key than 1.


In reply to Use of the => operator by roju

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.