Not so efficient, but output divided by words and counted. Sorting substrings alone is easy.
use strict; use warnings; my $words = 1; # Phrase must contain at least 1 word my $size = 5; # Phrase must be at least 5 characters long my $matches = 2; # Must be at least 2 copies of phrase my (@words, @pos, @matches, $p, $c, $key); $_ = join '', <DATA>; $_ = lc($_); @words = m/\w+(?:'\w+)?/g; @pos = sort { mycmp($a, $b) } 0..$#words; for $p ($words..$#pos) { $c = mycount($p); for (1..$c) { $key = join ' ', @words[$pos[$p]..($pos[$p]+$_-1)]; next if length($key) < $size; $matches[$_]{$key}++; } } for (reverse $words..$#matches) { print "$_ words:\n"; $c = $matches[$_]; for (sort { $c->{$b} <=> $c->{$a} } keys %$c) { last if $c->{$_} < $matches - 1; print " $_ : ",($c->{$_}+1),"\n"; } } sub mycount { my $x = $pos[$_[0]]; my $y = $pos[$_[0]-1]; my $c = 0; $c++ while $x <= $#words && $y <= $#words && $words[$x++] eq $word +s[$y++]; return $c; } sub mycmp { my ($x, $y) = @_; while ($x <= $#words && $y <= $#words) { return $c if $c = $words[$x++] cmp $words[$y++]; } return $x <=> $y; } __DATA__ Section. 1. All legislative Powers herein granted shall be vested in a Congress of + the United States, which shall consist of a Senate and House of Repr +esentatives. Section. 2. The House of Representatives shall be composed of Members chosen every + second Year by the People of the several States, and the Electors in + each State shall have the Qualifications requisite for Electors of t +he most numerous Branch of the State Legislature. No Person shall be a Representative who shall not have attained to the + Age of twenty five Years, and been seven Years a Citizen of the Unit +ed States, and who shall not, when elected, be an Inhabitant of that +State in which he shall be chosen.
I suppose I could write this to use a linear counting method of some sort, but that's for another day.

In reply to Re: Finding recurring phrases by TedPride
in thread Finding recurring phrases by Anonymous Monk

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.