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

RE: [FWP] Finding duplicated code



Peter Scott wrote:
>
> Step 3: Look for duplicated strings longer than, say, 150 characters:
> 
> 	print "---\n$1\n---\n" while /(.{150,}).*?\1/g;

Does this actually run?  In less than geological timeframes?  I'm impressed!
I would have thought that this type of regex would involve way too much 
backtracking...  This is definitely FWP...

> 
> One minuscule problem: the matches printed are on the 
> normalized string, 
> which is not as useful as the input string.  So I would like to map 
> backwards from a match in the normalized string to the input 
> string.  None 
> of the ways I can think of doing this make it nearly worth 
> the effort, 
> though :-)

Hmmm...  Maybe you could sort out from the string context which
package/sub the code fragments are in, and then print out the
original location of that?  That sounds feasible, but it's just
a guess...

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe