I would be more comfortable with a more familiar data structure organization. In addition to familiarity, I think it offers benefits when data elements are added/removed/mutated: as long as data element generation is encapsulated, there are no worries about construction and especially destruction.

>perl -wMstrict -MData::Dump -le "my @data = map data_element($_), [1, 2, 3,], [4, 5, 6,], [7, 8, 9,], ; ;; sub data_element { return { forward => $_[0], backward => [ reverse @{ $_[0] } ] }; } ;; dd \@data; $data[2]{forward}[1] == $data[2]{backward}[1] or die 'Oops...'; ;; ;; use constant { FWD => 0, REV => 1, }; ;; sub data_element2 { return [ @{[]}[FWD, REV] = ($_[0], [ reverse @{$_[0]}]) ]; } ;; my @data2 = map data_element2($_), [ 8, 7, 6, ], [ 5, 4, 3, ], [ 2, 1, 0, ], ; dd \@data2; $data2[0][FWD][1] == $data2[0][REV][1] or die 'Oops2...'; " [ { backward => [3, 2, 1], forward => [1, 2, 3] }, { backward => [6, 5, 4], forward => [4, 5, 6] }, { backward => [9, 8, 7], forward => [7, 8, 9] }, ] [ [[8, 7, 6], [6, 7, 8]], [[5, 4, 3], [3, 4, 5]], [[2, 1, 0], [0, 1, 2]], ]

In reply to Re^4: Allocation of anonymous arrays by AnomalousMonk
in thread Allocation of anonymous arrays by OwlHoot

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.