Forum Moderators: coopster & phranque

Message Too Old, No Replies

Storing and Re-applying String::Diff[erence]s

That String::Diff module

         

adni18

12:34 am on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey, I was wondering if anyone knows a good way to use the String::Diff module to take the difference between two strings, store them, maybe, then reapply them to the original string. Does anyone know how to do this?

Thanks!

Edit: I tried this with:

#!/usr/bin/perl

use Text::Diff;

$one="Smart";
$two="Poptart";

$diff = diff \$one, \$two;

print $diff;

but all it returned was:

@@ -1 +1 @@

perl_diver

1:50 am on Apr 9, 2006 (gmt 0)

10+ Year Member



what results were you expecting the module to return? What results are you wanting to return?

adni18

2:16 pm on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I was hoping the script would return something like:

CHG 0,3 "Popt"

or something that let the program call it later and reapply it to the string, like this:

$string1="blah";
$string1="sarah";
$joe=diff($string1, $string2);

# save $joe to a file then recall contents as $sam

$newspl = appl($sam, $string1);

# $newspl is "sarah"

perl_diver

7:33 pm on Apr 9, 2006 (gmt 0)

10+ Year Member



How representative of the real data you will be using are the example strings you posted? The examples are very simple and could made to work failry easily, but for more complex strings it could be a real pain in the tush. Check your sticky mail.