There's more than one way to do things | |
PerlMonks |
Re: [OT] Finding similar program codeby bliako (Monsignor) |
on Aug 27, 2021 at 12:35 UTC ( [id://11136132]=note: print w/replies, xml ) | Need Help?? |
I would first try to make the code look as simple as possible (from the point of view of a pattern matching algorithm. Not a human). For example, why have all kind of whitespace instead of just one, a newline say (EDIT: or none at all)? You can compress the code a bit by replacing repeated, small chunks of it with a word from compression-vocabulary. So that pattern matchings can be faster. For example ActiveSheet.Cells can become _ASC_. If there was a VBA-to-bytecode, it could be used instead of the above (perhaps). (EDIT: no, unless you can convert it back to VBA code.) After that, your task may be similar to DNA matching. And there exist efficient algorithms (implemented) for doing that and spotting common sections between 2 DNA sequences. See Boyer–Moore_string-search_algorithm. And also this for more food for thought: https://www.hindawi.com/journals/bmri/2019/7074387/ Of course there are linguistic approaches to this too (but code is NOT human-text): https://www.baeldung.com/cs/ml-similarities-in-text and https://towardsdatascience.com/the-best-document-similarity-algorithm-in-2020-a-beginners-guide-a01b9ef8cf05 will give you ideas. bw, bliako
In Section
Seekers of Perl Wisdom
|
|