As per an earlier suggestion, I have used Text::Diff to work out the diffs between two sets of word arrays but what I need to do is to split the results on the + sign to eventually wrap them up in XML for an AJAX application.
I get the result:
Scrooge never painted out old Marley's name + Nermal never painted out old Marley's name
What I'd like is:
Scrooge never painted out old Marley's name
Nermal never painted out old Marley's name
Is it possible to split on +? If not, can it be swapped and split on that instead?
#!c:\perl\bin\perl.exe use strict; use warnings; use DBI; use Text::Diff; use IO::File; my $diff; my $dbh; #Create the strings first $dbh = DBI->connect('dbi:mysql:dickens:localhost', 'admin', 'pass'); #my ($indexstring) = $dbh->selectrow_array('SELECT sentence FROM seque +nce'); #my ($additionaltext) = $dbh->selectrow_array('SELECT sentence FROM se +quence1'); my @indexstring; my @additionaltext; my $result; my $sth = $dbh->prepare("SELECT sentence FROM sequence"); $sth->execute; while (my @result = $sth->fetchrow_array) { push @indexstring,$result[0]; } $sth = $dbh->prepare("SELECT sentence FROM sequence1"); $sth->execute; while (my @result = $sth->fetchrow_array) { push @additionaltext,$result[0]; } $dbh->disconnect(); ################################ #Compare strings or arrays ################################ #Use Text::Diff for arrays. #Need a regex to get the relevant data out my @difference = diff \@indexstring, \@additionaltext; foreach $diff(@difference) { my $unequal = split(/+/, $diff); print "$unequal\n"; }
Is there, perhaps, a better of doing this (though this nearly gives the me the results I'd love)?

In reply to Splitting on + after using Text::Diff by Quicksilver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.