in reply to Perl For loops
Given that, the loop is just aborting once a 0 values is hit. We also know that the length of the outer array in the result is the count of the first inner array in the matrix. Thus:
The result of both your code and mine is the same:my @matrix=([qw(1 2 4 4)],[qw(5 2 0 8)],[qw(9 10 11 12)],); my @t; for my $i (0..$#{$matrix[0]}) { for my $j (0..$#matrix) { last if $matrix[$j][$i] == 0; $t[$i][$j] = $matrix[$j][$i]; } }
Update: I must have missed Util's comment, which is virtually identical to mine :)$VAR1 = [ [ 1, 5, 9 ], [ 2, 2, 10 ], [ 4 ], [ 4, 8, 12 ], ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl For loops
by atemon (Chaplain) on Jul 04, 2007 at 07:31 UTC | |
by aufflick (Deacon) on Jul 06, 2007 at 03:34 UTC |