So for the sake of completeness, and posterity... and not because anyone cares, here's the final version that I decided fixed things up the way I wanted. Turns out by reordering the substr I was able to remove the space ambiguity I was seeing in one of my example data failures where I was getting nested span tags.
sub spandiffstr {
my ( $old, $new ) = @_;
my $span = '<span>';
my $espan = '</span>';
( $old ^ $new ) =~ /^\0*/ and my $subscr = $+[0];
substr $old, $subscr, 0, $span;
substr $new, $subscr, 0, $span;
my ( $rold, $rnew ) = map scalar reverse, $old, $new;
( $rold ^ $rnew ) =~ /^\0*/ and my $lsubscr = -$+[0];
my $losubscr = $lsubscr;
unless ($lsubscr) {
$losubscr = length $old;
$lsubscr = length $new;
}
substr $old, $losubscr, 0, $espan;
substr $new, $lsubscr, 0, $espan;
return $old, $new;
}
Thanks for all the fish!
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.