Our $work style guide says to use no quotes and no spaces for such hash keys because it is easier to search for {word} than for any of {word}, { word }, {"word"}, {'word'}, and some more obscure styles of quoting. Similarly, you can search for /\bword\s*=>/ more easily than trying to guess what type of quoting might be used; and adding quotes means somebody might not have even used =>.

On rare occasions, you have a mix of bareword keys and keys with hyphens or dots and have to mix: word => $word, 'non-word' => $non_word. But I have not found that to be a disadvantage.

Of course, the advantage is fairly minor in the scheme of things.

Then there is the idea of avoiding retyping such key names where a typo won't be caught for you and so you define constants for your keys and end up with $WORD => $word or WORD() => $word. Or just avoid using a hash and use separate variables (especially for command-line options).

- tye        


In reply to Re: Optional quotes: to use or not to (fewer ways) by tye
in thread Optional quotes: to use or not to by hurricup

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.