3

I'm comparing a template to the output based on that template, so I need to produce sdiff output that is tolerant of specified changes; essentially I want the template line:

Foo bar blarg [TAG] lorem ipsum 

to match any of

Foo bar blarg .+ lorem ipsum

rather than being reported as changed.

What's the easiest way to go about this?

Miller
  • 34,962
  • 4
  • 39
  • 60
MilitaryCoo
  • 111
  • 1
  • 7
  • 2
    On the face of it, preprocess the template line into the appropriate regular expression, and then compare the file line with the template-line-as-regex. So, read a line from the template and convert it to a regex; read a line from the other file, and see if it matches the template regex. That doesn't sound like Algorithm::Diff, though. It also leaves you with resynchronization problems if your other file has extra lines or missing lines. – Jonathan Leffler Jun 26 '14 at 14:35
  • I'd like to use some form of the Diff module to take advantage of the minimal set of changes it returns. – MilitaryCoo Jun 27 '14 at 09:06
  • Are you sure that none of your `[TAG]` values are multi-line strings? If so, you can try using lines from the template modified into regular expressions to detect the expanded forms in the other file and replace the expansion with `[TAG]` notation, and then run a Diff algorithm on the template (original) file and the unexpanded version of the other file. Otherwise, go scanning http://search.cpan.org/ for ideas. If there isn't a module that does what you need, you could consider writing one, but it won't be trivial. If you have multi-line replacements for tags, life is much harder. – Jonathan Leffler Jun 27 '14 at 14:10
  • I already do preprocessing to convert any multiline tags into multiple single-line tags. Using the template to fix the output before comparison defeats the purpose of the diff step -- if I'm doing line-by-line comparison I might as well just do the comparison in those steps. I'll have a look at search.cpan – MilitaryCoo Jun 28 '14 at 13:16
  • 1
    Could you provide samples of your template and output files along with details of what should and shouldn't be considered as a difference? I suspect that you could use Algorithm::Diff::traverse_balanced and handle ignoring false positives in the callbacks for differences. – Michael Carman Sep 12 '14 at 16:42

0 Answers0