I think what I need is an Array of Array of Hash, but I have no idea how to make that.
Can Perl do that?
And if so, how would the code look like?
I think what I need is an Array of Array of Hash, but I have no idea how to make that.
Can Perl do that?
And if so, how would the code look like?
You can address elements of such a data structure thus:
$x->[1][2]{foo} = "hello"
You don't even have to pre-define the structure. Just start working with the elements as if they're already there.
$a (or $b) in examples that don't involve sort. $a and $b are special variables in Perl and can cause odd errors when used outside of a function passed to sort.my $aah =
[ # outer array
[ # first inner array
{ # first inner hash
foo => 'bar',
},
{ # second inner hash
bar => 'baaz',
},
],
[ # secnd inner array
#...
],
# ...
];
You can access the elements like this:
$aah->[0]->[1]->{bar} # => 'baaz'
$aah->[0][1]{bar}... everything in an array or hash is a scalar, thus any substructures can be assumed to be references, thus only the first arrow is ever needed.$$arr[0][1]{bar}. I personally prefer that over the -> notation.my $arr =
[
[
{key1 => $value1, key2 => $value2},
{key1 => $value3}
],
[
{rubbish => 'nonsense'},
]
];
etc.