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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |