Actually, i think that using an array of array references is a wonderful fit for this problem. You just need to familiarize yourself with how Perl dereferences them:
But, having said that, whenever i need a "real" Matrix, i use Math::Matrix. Wonderful module. :) And, it too uses an array reference of array references to store the matrix in:my $two_d = [ [1,2,3], [4,5,6], [7,8,9], ]; # how many columns? print scalar @$two_d; # how many rows in second column? print scalar @{ $two_d->[1] };
but the benefits of using the module instead of rolling your own are the helper methods such as size() and transpose().use Math::Matrix; use Data::Dumper; my $two_d = [ [1,2,3], [4,5,6], [7,8,9], ]; my $m = Math::Matrix->new($two_d); print Dumper $m;
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: Resizable Matrix, or similar data structure.
by jeffa
in thread Resizable Matrix, or similar data structure.
by PerlingTheUK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |