Gilles wrote:
Hi,
I would like to create a matrix 9x9 where the elements are list (array).
(like a cube)
These lists will decrease during processing and will normally contain one
element, so to know if a list is definitely treated I need a flag.
So 2 solutions seems to be good, but which one do you think will be easier
to use :
- an array of array of array with as flag a special value at the
end of the last array
- an array of array of hash with one key for the list of value and
one key for the flag
In the 2 solutions, I'm not sure to know how to access the lists I have to
modify !
Could you help me please
Thanks
Gilles
The best way to use a multi-dimensional array is to simply use it:
my @array = ();
# Adding an item to the $i, $j element
push @{ $array[$i][$j] }, $item;
# Retrieving an item
$item = pop @{ $array[$i][$j] };
# Accessing the $k item
$item = $array[$i][$j][$k];
# Iterating over a list
for my $item ( @{ $array[$i][$j] } ){
# Any change to $item will change
# the element in the list @{$array[$i][$j]}
}
# To see inside the matrix
use Data::Dumper;
print Dumper( [EMAIL PROTECTED] );
# For your other problem, I would simply keep a separate array.
my @Processed = ();
# for all $i, $j
unless( $Processed[$i][$j] ){
# Process @{$array[$i][$j]}
$Processed[$i][$j] = 1;
}
--
Just my 0.00000002 million dollars worth,
--- Shawn
"Probability is now one. Any problems that are left are your own."
SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>