in reply to Creating multidimentional arrays dynamically
push @{$x[5]}, $value;
The nice thing: it does not matter whether row 5 existed before, it will be created when needed (this is called autovivication)
To remove values from the end of a row you use pop
$value= pop @{$x[5]};
To remove the first value instead use shift:
$value= shift @{$x[5]};
To remove or add values into the middle of an array use splice. Do 'perldoc -f splice' on the command line to read more about that
To access one or all values of row 5 or all rows you do this:
#access one value in row 5 $n= $x[5][4]; #access all values in row 5 foreach $n ( @{$x[5]} ) { } #access all values in @x foreach $row ( @x ) { foreach $n ( @$row ) { }
The syntax @$row is shorthand for @{$row} which you have seen above
|
|---|