in reply to Re: syntax error
in thread syntax error

I never realized that auto-quoting of keys depends on identifier rules.

Identifiers are not allowed to start with digits, like it's not allowed to call a

sub 1586i { ... }

UPDATE:

though it's possible to have a pure digit key (?)

DB<113> p $h{1586}++ 1 DB<114> p $h{1586}++ 2

strange ...

Update

so I couldn't find it documented, but the rule seems to be:

In order to autoquote a hash key it has to be a legal identifier or a number.

in this case the number is found and Perl thinks an operator is missing to separate it from the bareword.

from perlglossary

identifier

A legally formed name for most anything in which a computer program might be interested. Many languages (including Perl) allow identifiers to start with an alphabetic character, and then contain alphabetics and digits. Perl also allows connector punctuation like the underscore character wherever it allows alphabetics. (Perl also has more complicated names, like qualified names.)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^3: syntax error
by haukex (Archbishop) on Jun 20, 2017 at 15:20 UTC

    See my post here for a lot of examples and explanation :-) In short, from perldata:

    ... a simple identifier within such curlies is forced to be a string, and likewise within a hash subscript. Neither need quoting. ... This means for example that $version{2.0}++ is equivalent to $version{2}++, not to $version{'2.0'}++.

    $h{1586} works because it's interpreted as an integer, so something like $h{0+1586}, which stringifies to "1586".