#!/usr/bin/perl ## LONGEST COMMON SUBSTRINGS (sorted) from a set of given sequences: use strict; use warnings; sub LCS { # Line 5 my ($ctx, $a, $b) = @_; my ($amin, $amax, $bmin, $bmax) = (0, $#$a, 0, $#$b); while ($amin <= $amax and $bmin <= $bmax and $a->[$amin] eq $b->[$bmin]) { $amin++; $bmin++; } while ($amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax]) { $amax--; $bmax--; } # Line 15 my $h = $ctx->line_map(@$b[$bmin..$bmax]); # line numbers are off by $bmin return $amin + _core_loop($ctx, $a, $amin, $amax, $h) + ($#$a - $amax) unless wantarray; my @lcs = _core_loop($ctx,$a,$amin,$amax,$h); if ($bmin > 0) { # Line 20 $_->[1] += $bmin for @lcs; # correct line numbers } map([$_ => $_], 0 .. ($amin-1)), @lcs, map([$_ => ++$bmax], ($amax+1) .. $#$a); } sub a { my $match = CSS(@_); # line 28 if ( ref $_[0] eq 'ARRAY' ) { @$match = map{$_->[0]}sort{$b->[1]<=>$a->[1]}map{[$_,scalar(@$_)]}@$match } else { # Line 32 @$match = map{$_->[0]}sort{$b->[1]<=>$a->[1]}map{[$_,length($_)]}@$match } return $match; } ## Data Input & Results: # Line 37 print"\nThe longest common substrings in decreasing order of lengths:\n"; my $result1=a qw(ABABC BABCA ABCBA); my $leng1=$result1; # Line 40 print"\n$result1; Length=$leng1\n\n"; exit;