in reply to Re^4: Array wierdness -- initialize AoA
in thread Array wierdness
That's usually not what you want: that'll give you three copies of the same arrayref, so if you later modify an element in one row it'll modify it in all rows:
% perl -wle '@aoa = ([(1) x 3]) x 3; $aoa[1][2] = 3; print "@$_" for @ +aoa' 1 1 3 1 1 3 1 1 3
If you want each element to be independent, a typical approach is to pass it through map:
% perl -wle '@aoa = map [(1) x 3], 1..3; $aoa[1][2] = 3; print "@$_" f +or @aoa' 1 1 1 1 1 3 1 1 1
|
|---|