Bod, broader than just hashes, I encourage you to spend considerable time studying and thinking about cool ways to use Perl's many and varied ways of quoting! Time well spent. At least, this is one area where I've found Perl to be (easily) the most enjoyable language I've ever used. Perl's heredocs with variable interpolation, for example, I've found to be a joy compared to wrestling with Python's ugly triple-quoted multi-line strings.

Some examples from PBP Chapter 4 (Values and Expressions), will hopefully give you a feel for where I'm coming from.

While I tend to favour the q{form-of-quoting} by default, for example:

my $publisher = q{O'Reilly};

PBP gives an example showcasing how Perl allowing you to choose a different delimiter can clarify the code (by eliminating ugly escaping), making it easier to understand at a glance:

my $title = q[Perl Best Practices]; my $publisher = q[O'Reilly]; my $end_of_block = q[}]; my $closing_delim = q['}]; my $citation = qq[$title ($publisher)];

The fat-comma is also worthy of study. Conway, for example, finds this version more pleasing to the eye:

%default_service_record = ( name => '<unknown>', rank => 'Recruit', serial => undef, unit => ['Training platoon'], duty => ['Basic training'], );
than this one:
%default_service_record = ( 'name', '<unknown>', 'rank', 'Recruit', 'serial', undef, 'unit', ['Training platoon'], 'duty', ['Basic training'], );

References


In reply to Re: Quoting hash keys by eyepopslikeamosquito
in thread Quoting hash keys by Bod

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.