It's just that I thought steps had been taken to avoid the need for quoting hash keys
From "Learning Perl (5th)", p 95:
...the keys are always converted to strings. So, if you used the numeric expression 50/20 as the key, it would be turned into the three-character string "2.5"...
And on p. 254, in a section titled "Unquoted Hash Keys":
Perl offers many shortcuts that can help programmers. Here's a handy one: you may omit the quote marks on some hash keys.
Of course, you can't omit the quote marks on just any key, since a hash key may be any arbitrary string. But keys are often simple. If the hash key is made up of nothing but letters, digits, and underscores without starting with a digit, you may be able to omit the quote marks. This kind of simple string without quote marks is called a bareword, since it stands alone without quotes.
...But beware: if there's anything inside the curly braces besides a bareword, Perl will interpret it as an expression.
| [reply] |
It's just that I thought steps had been taken to avoid the need for quoting hash keys .... that's obviously not so and we're left with what looks like a dog's breakfast when it comes to deciding if a key needs to be quoted or not.
The rule seems pretty straightforward to me. If the hash key is a valid identifier, it doesn't need quoted. Otherwise it does. Has always worked fine for my usage and always does what I want.
| [reply] |