Is this what you are looking for?
#!/usr/bin/perl # http://perlmonks.org/?node_id=1144405 use Algorithm::Diff qw(traverse_sequences); use strict; use warnings; my $S=" MSATPLTQEQKKA"; my $T=" MNATLTQQTKA"; my @from = split //, shift // $S; my @to = split //, shift // $T; my $top = ''; my $bottom = ''; traverse_sequences( \@from, \@to, { MATCH => sub {print $from[shift()]}, MATCH => sub {$top .= $from[shift()]; $bottom .= $to[pop()]}, DISCARD_A => sub {$top .= $from[shift()]; $bottom .= ' '}, DISCARD_B => sub {$top .= ' '; $bottom .= $to[pop()]}, } ); print "$top\n$bottom\n";
This outputs:
MS ATPLTQEQK KA M NAT LTQ Q TKA
These two sequences are aligned by common character.
Please show inputs and desired output when you ask for help.
Giving several test cases is always a good idea.
In reply to Re: Perl Array
by Anonymous Monk
in thread Perl Array
by baconyluv5
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |