inblosam has asked for the wisdom of the Perl Monks concerning the following question:

This module (Text::ParagraphDiff) is nice for comparing texts (more so manuscripts than code). It works great using two files for comparison, but now when I try to just put in straight text, I can't get the line breaks to be accepted. I have tried as the code is below, and also directly from some text in a database, to no avail. The same text from the database put into a file works fine when I use the file method.
#!/usr/bin/perl -w use strict; use Text::ParagraphDiff; my $copy_old = qq|the first line the second line is here this really should be on separate lines, no? weird eh?|; my $copy_new = qq|the FIRST line the second line is there not here this really should be on sequential lines, no? weird huh?|; #THIS IS THE DIRECT TEXT METHOD #THAT LINE BREAKS GET IGNORED print text_diff(["$copy_old"], ["$copy_new"]);
and the other way is:
#THIS IS THE FILE METHOD THAT WORKS #AND DOESN"T IGNORE LINE BREAKS print text_diff('/somepath/old.txt','/somepath/new.txt');

I have tried substituting various end of line characters like:
$copy_old =~ s/\n/\r\n/;
or
$copy_old =~ s/\r\n/\n\n\n\n/;

Could it be something in the module itself? I tried to look through the code, but it is above my level of experience.

I have lots of text that must maintain the line breaks for it to make sense. Any help would be greatly appreciated! Thanks!


Michael Jensen

Replies are listed 'Best First'.
Re: Line breaks being ignored?
by duff (Parson) on Dec 05, 2003 at 05:04 UTC

    I believe (looking at the module's documentation) that it expects individual lines to be passed as elements of arrays which you provide references to in text_diff. So, I think you need this:

    #!/usr/bin/perl -w use strict; use Text::ParagraphDiff; my $copy_old = qq|the first line the second line is here this really should be on separate lines, no? weird eh?|; my $copy_new = qq|the FIRST line the second line is there not here this really should be on sequential lines, no? weird huh?|; print text_diff([split /\n/,$copy_old], [split /\n/,$copy_new]);

    Hope this helps

      Okay, I would have never thought of that! THANKS!! Works like a charm. You are super!


      Michael Jensen