[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] repeated substrings



>From vlb@cfcl.com  Wed Jun 23 11:54:32 1999 - sorry for the delay]
Message-ID: <01BEBD6D.D20F5E20@ERIC.nextest.com>
Date: Wed, 23 Jun 1999 11:44:57 -0700

If we're looking for the longest repeated substring,
why not _start_ looking for the longest (which can
after all at most be only half as long as the string)?

Efficiency can be fun too.  At least sometimes...


$_ = "a thing that something will check";

for ( $n = length >> 1; $n; --$n ) { $res = $1 and last if /(.{$n}).*\1/ }

or

for ( $n = length >> 1; $n; --$n ) { return $1 if /(.{$n}).*\1/ }

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org