a solution with O(NlogN) cost and with low memory consumption:
use strict; use warnings; my $data = do { local $/; lc <DATA> }; my @words = $data =~ /\w+/g; { no warnings; sub cmpix { for (my $off = 0;; $off++) { my $cmp = $words[$a+$off] cmp $words[$b+$off]; return $cmp if $cmp; } } } my @ixs = sort cmpix 0..$#words; # replace this code with duplication detector (it # should be easy!): for my $ix (@ixs) { print substr(join(" ", @words[$ix..$#words]), 0, 50), "\n"; } __DATA__ ...
that outputs...
$ perl ./t.pl 1519 2nd may 1519 a character in the discworld series of novels is b at clos luc france on 2nd may 1519 based largely on leonardo da vinci leonardo da vin character in the discworld series of novels is bas clos luc france on 2nd may 1519 da vinci died at clos luc france on 2nd may 1519 da vinci leonardo da vinci died at clos luc france died at clos luc france on 2nd may 1519 discworld series of novels is based largely on leo france on 2nd may 1519 in the discworld series of novels is based largely is based largely on leonardo da vinci leonardo da largely on leonardo da vinci leonardo da vinci die leonard of quirm a character in the discworld seri leonardo da vinci died at clos luc france on 2nd m leonardo da vinci leonardo da vinci died at clos l luc france on 2nd may 1519 may 1519 novels is based largely on leonardo da vinci leona of novels is based largely on leonardo da vinci le of quirm a character in the discworld series of no on 2nd may 1519 on leonardo da vinci leonardo da vinci died at clo quirm a character in the discworld series of novel series of novels is based largely on leonardo da v the discworld series of novels is based largely on vinci died at clos luc france on 2nd may 1519 vinci leonardo da vinci died at clos luc france on
then finding duplicates is pretty obvious as they appear in consecutive entries in @ixs.

In reply to Re: Finding recurring phrases by salva
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.