perl -MData::Dumper -E '$A[3][5][0]="foo"; die Dumper \@A'
output:
$VAR1 = [
undef,
undef,
undef,
[
undef,
undef,
undef,
undef,
undef,
[
'foo'
]
]
];
Long? Just try 300 by 500!
perl -MData::Dumper -E '$A{3}{5}{0}="foo"; die Dumper \%A'
output:
$VAR1 = {
'3' => {
'5' => {
'0' => 'foo'
}
}
};
smaller, but slower to iterate through if you have lots of entries. Still you can use an intermediate variable that acts like a pointer:
perl -MData::Dumper -E '$A{3}{5}{0}="foo"; $v = $A{3}{5}; $v->{1}="bar
+"; die Dumper \%A'
if you have fixed dimensions... you can also try: $NUM = $x + $y*$WIDTH
so if you have 300 pixels wide, (x,y)=(3,5) becomes 3+5*300 = 1503
but check if you will not run above your maxint: 718414 with that method
|