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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.