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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.