
Chris Charley
User
Sep 8, 2012, 9:27 AM
Views: 2723
|
|
Re: [rushadrena] A file parsing and 2D array/matrix problem.
|
|
|
The way you have set up the for loops is wrong, (I'll show below), and does not interface with the rest of the program. I believe you want the pairings of each matrix, (and not the matrix by itself). That seems to be the intention of your attempt to solve the problem. You also have other issues which you have been discussing with Laurent. How to find the files, etc. To find all pairs, I set up a table from 1 to 5, (instead of 1 to 10), just to demonstrate combinations. #!/usr/bin/perl use strict; use warnings; for (my $i=1;$i<=5;$i++) { for (my $j=1;$j<=5;$j++) { print "($i $j)\n"; } } print "\ncombinations\n"; for (my $i=1;$i<=5;$i++) { for (my $j=$i+1;$j<=5;$j++) { print "($i $j)\n"; } } __END__ C:\Old_Data\perlp>perl t7.pl (1 1) duplicate (1 2) (1 3) (1 4) (1 5) (2 1) done earlier (1 2) (2 2) duplicate (2 3) (2 4) (2 5) (3 1) done earlier (1 3) (3 2) done earlier (2 3) (3 3) duplicate (3 4) (3 5) (4 1) done earlier (1 4) (4 2) done earlier (2 4) (4 3) done earlier (3 4) (4 4) duplicate (4 5) (5 1) done earlier (1 5) (5 2) done earlier (2 5) (5 3) done earlier (3 5) (5 4) done earlier (4 5) (5 5) duplicate combinations (1 2) (1 3) (1 4) (1 5) (2 3) (2 4) (2 5) (3 4) (3 5) (4 5) C:\Old_Data\perlp> You can see in the first column that some pairs have already been seen, just in reverse order, (1 2) and (2 1) for example. Note: arrays in Perl begin with 0 and not 1.
(This post was edited by Chris Charley on Sep 8, 2012, 11:25 AM)
|