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
|