Me again
I have another problem with the script and since I frankly don't fully understand it, I ask again here:
Please look at the output of:
use strict; use warnings; use Algorithm::Diff qw( ); my @seqs = ( [qw( A B C D E F G H I )], [qw( A D C X F G H I )], # [qw( A )], # [qw( A B C )], ); my @combined; my @grid; for my $col_idx (0..$#seqs) { my $seq = $seqs[$col_idx]; my $diff = Algorithm::Diff->new(\@combined, $seq); my @new_combined; my @new_grid; while ($diff->Next()) { if ($diff->Same()) { for ($diff->Range(1)) { push @new_combined, $combined[$_]; push @new_grid, $grid[$_]; $new_grid[-1][$col_idx] = 1; } } else { for ($diff->Range(1)) { push @new_combined, $combined[$_]; push @new_grid, $grid[$_]; } for ($diff->Range(2)) { push @new_combined, $seq->[$_]; push @new_grid, []; $new_grid[-1][$col_idx] = 1; } } } @combined = @new_combined; @grid = @new_grid; } for my $row_idx (0..$#combined) { my $ch = $combined[$row_idx]; for my $col_idx (0..$#seqs) { print($grid[$row_idx][$col_idx] ? $ch : " ", " "); } print("\n"); }
It outputs
A A B C D D E C X F F G G H H I I
What I want is:
A A B B C C D X E F F G G H H I I
The rows must be, so to say, unique, meaning that there must not be a "C" in line 3 and one in line "6". What I also wonder is: The Documentation of Algorithm:Diff reads that if finds the LCS. But for my example it finds 6 common rows while I find 7 ...
Greetings,
Jan
In reply to Re^3: Converting Arrays into Matrix
by Anonymous Monk
in thread Converting Arrays into Matrix
by janDD
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |