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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
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.
|
|