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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|