Valid unquoted strings, such as bare literal hash keys, consist of \w characters only. They are: A-Za-z0-9 and underscore (_). You can have leading or trailing whitespace, which can come in handy. Hoewever, the - character is not allowed, and forces it to be a normal expression.

Without strict, it's allowed, because without strict it's allowed to use unquoted strings everywhere, not only in literal hash keys and the left operand of the => operator.

# Assuming you don't have subs called POWER and/or NODE. no strict; $run{POWER-NODE} = yes; # equals: $run{ 'POWER' - 'NODE' } = 'yes'; # equals: $run{ 0 - 0 } = 'yes'; # and thus: $run{0} = 'yes';
Consider:
$foo{99-24} = "Hello, world!\n"; print $foo{75};


With strict, you can't use the unquoted strings POWER, NODE and yes. You'll have to add quotes as such: $run{'POWER-NODE'} = 'yes'. When you get rid of the -, and use an underscore instead, you can use an unquoted string after all (strict makes an exception for =>'s left operand, and for literal constant hash keys) like this: $run{POWER_NODE} = 'yes'.

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk


In reply to Re: Hash table key names with a by Juerd
in thread Hash table key names with a minus by Rhodium

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.