Good day perlfolk,
I often work with data matrices (lists of lists) in my scripts. A simple example is:
@matrix = ();
@list1 = ("one","two","three");
@list2 = ("four","five","six");
@list3 = ("seven","eight","nine");
@list4 = ("ten","eleven","twelve");
push @matrix, [ @list1 ];
push @matrix, [ @list2 ];
push @matrix, [ @list3 ];
push @matrix, [ @list4 ];
Sometimes I want to extract one row, like maybe the third one, shortening the matrix
and putting the row in another list. The only method I've found so far that works is
the tedious one of using for loops to iterate through the matrix and create two new
matrices, one that contains the row(s) I want, and one the row(s) I don't currently
want, discarding the original matrix. I've tried using different variations of splice
(sample below) to accomplish the creation of the "wanted" and "unwanted" matrices, but
have had no success.
$row_elements = $#list4;
splice(@new_list,0,$row_elements,splice(@matrix,2,$row_elements));
None of the common Perl books talk about this. Chapter 7 of Mastering Algorithms with
Perl talks about two modules for dealing with matrices, Math::MatrixReal and PDL. PDL
is only available on CPAN and does not install correctly on Win32. The other module
has an unusual one-indexing feature (the upper left element of a matrix is 1,1 - not
0,0 as in regular lists) that I don't want to use because I'm sure I'll get confused
working with indices on different types of lists. Plus, I'd rather not install yet
another module to do something that could be accomplished with a function. Anyone
working with matrices and splice? I could use a hand understanding this.
TIA,
Glen
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users