in reply to Re^2: Hash keys not DWIMming
in thread Hash keys not DWIMming
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.
|
|---|