in reply to Re^2: Identifying Overlapping Area in a Set of Strings
in thread Identifying Overlapping Area in a Set of Strings
How can I modify your code such that it simply gives: ...
Quite simple:
my @results; my %seen; for (1 .. $#nsub) { my $current = $nsub[$_]; my $previous = $nsub[$_ -1]; if ( "$previous#$current" =~ /(\w+)#\1/ ) { my $found = $1; printf "%d -> %s (%s) %d -> %s \n", $_ -1, $previous, $found, $_, $current; $current =~ s/^$found/"-" x length($found)/e; $previous =~ s/$found$/"-" x length($found)/e; push @results, [ $_ -1, $previous] unless $seen{$_ -1}++; push @results, [ $_, $current] unless $seen{$_}++; } else { printf "%d -> no overlap\n", $_ } } print Data::Dumper->Dump([ \@results], ['result']);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Identifying Overlapping Area in a Set of Strings
by monkfan (Curate) on Jul 30, 2005 at 04:01 UTC |