Hi monks

How to compare two variables which has values a line and print the specific unmatched word by its position and line number

for example

$str1 = "But I think the device doesn't allow writes or something and +that's causing this issue."; $str2 = "But I think the device allow writes or something and that's c +ausing this issue.";
open (FHH, ">error.txt")|| die $!; $str1 = "But I think the device doesn't allow writes or something and +that's causing this issue."; $str2 = "But I think the device allow writes or something and that's c +ausing this issue."; my $line = 0; my $pat = qr/$str2/; while($str1){ $line++; if($str1 =~m/($pat)/igs){ my $pre = $`; } else{ print FHH "Line $line:$pre \'$pat\' is missing from $str2." } }

In the $str2 dont have "doesn't" as compare to $str1

So the output will be in other file called error.txt in this format: Line 1:cols 24 'doesn't' is missing from $str2

I have tried some modules in perl like: File::Compare, Text::Compare, List::Compare but they are not giving the proper answer.

Which strategy should I choose to get multiple lines store in two variables like a two whole file is store in two different variable and compare 2nd file on 1st and print position of mismatch in other file.

Please Help!

Thanks in advance

In reply to How to campare two variable consist line and print difference by Mjpaddy

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.