If there are more lines to follow in your file and you want to automatically detect the end of the pattern without specifying the pattern explicitly, you can use the module String::Similarity, for example:

use strict; use warnings; use String::Similarity; my $string; $string .= "abc($_) = xyz(".($_-1).");\n" for 1..10; $string .= "not similar\n"; my @lines = split /\n/, $string; for (1..$#lines) { print "\"".$lines[$_-1]."\" == \"".$lines[$_]."\" ? "; print similarity $lines[$_-1], $lines[$_]; print "\n"; }

gives the following output

"abc(1) = xyz(0);" == "abc(2) = xyz(1);" ? 0.875 "abc(2) = xyz(1);" == "abc(3) = xyz(2);" ? 0.875 "abc(3) = xyz(2);" == "abc(4) = xyz(3);" ? 0.875 "abc(4) = xyz(3);" == "abc(5) = xyz(4);" ? 0.875 "abc(5) = xyz(4);" == "abc(6) = xyz(5);" ? 0.875 "abc(6) = xyz(5);" == "abc(7) = xyz(6);" ? 0.875 "abc(7) = xyz(6);" == "abc(8) = xyz(7);" ? 0.875 "abc(8) = xyz(7);" == "abc(9) = xyz(8);" ? 0.875 "abc(9) = xyz(8);" == "abc(10) = xyz(9);" ? 0.848484848484849 "abc(10) = xyz(9);" == "not similar" ? 0.0714285714285714

In reply to Re: Finding the last statement in string of atmost similar pattern by hdb
in thread Finding the last statement in string of atmost similar pattern by amma

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.