Would something like the Levenshtein edit distance assist you (the greater the value, the greater the two strings' distance)?
use strict;
use warnings;
use Text::LevenshteinXS qw(distance);
my @var;
$var[0] = "Gallia est omnis divisa in partes tres";
$var[1] = "Gallia est omnis divisa in ...";
$var[2] = "Gallia est omnis ...";
$var[3] = "Gallia";
$var[4] = "... omnis divisa in ...";
$var[5] = "Gallia est ... tres";
$var[6] = "Gallia ... partes tres";
$var[7] = "Gallia est ... partes tres";
$var[8] = "Gallia ... divisa ... tres";
$var[9] = "... tres";
$var[10] = "quattuor";
print qq{Each string's 'distance' from "$var[0]":\n\n};
for ( 0 .. $#var ) {
print distance( $var[0], $var[$_] ) . " - $var[$_]\n";
}
Output:
Each string's 'distance' from "Gallia est omnis divisa in partes tres"
+:
0 - Gallia est omnis divisa in partes tres
11 - Gallia est omnis divisa in ...
21 - Gallia est omnis ...
32 - Gallia
21 - ... omnis divisa in ...
22 - Gallia est ... tres
19 - Gallia ... partes tres
15 - Gallia est ... partes tres
18 - Gallia ... divisa ... tres
33 - ... tres
34 - quattuor
-
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.
|