Whether the code becomes clearer when using a big hash is subjective. In your example, you got away by not having to use a different order of the fields than you define, but the original code doesn't have that luxery, as the output has the fields in a different order than the input.

Which means, you either have to use string literals as key names or put the field names into separate variables. The former loses you some of the benefits of using 'use strict' as misspellings in field names aren't found by the compiler (and not even by the runtime, 'use warnings' won't help you either). In the latter case, you're just shifting what you are trying to avoid. There's little difference in:

my %big_hash; my $field_name1 = "field_name1"; my $field_name2 = "field_name2"; ... $big_hash{$key}{$field_name1} $big_hash{$key}{$field_name2} ...
or
my %field_name1; my %field_name2; ... $field_name1{$key} $field_name2{$key}
I don't want to dogma "always group in a big hash instead of using parallel datastructures", nor the opposite. There are pros and cons.

In reply to Re^4: If Statements and Regular Expressions by JavaFan
in thread If Statements and Regular Expressions by TempAcolyte

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.