Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Comparing string characters

by choroba (Cardinal)
on Nov 22, 2021 at 16:42 UTC ( [id://11139027]=note: print w/replies, xml ) Need Help??


in reply to Comparing string characters

It seems like you're interested in the edit distance. There are several different algorithms, and the most well-known is Levenshtein distance, implemented for example by Text::Levenshtein.
#!/usr/bin/perl use warnings; use strict; use Text::Levenshtein qw{ distance }; use Test::More tests => 3; is distance('ABCGE', 'ABCGE'), 0; is distance('ABCGE', 'FGCGB'), 3; is distance('ABCGE', 'JHAGT'), 4;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Comparing string characters
by dnamonk (Acolyte) on Nov 22, 2021 at 18:19 UTC
    Thanks. That was really helpful :)
Re^2: Comparing string characters
by LanX (Saint) on Nov 22, 2021 at 17:42 UTC
    Levenshtein might be overkill, I can't see a requirement for "edit distance" in these samples

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found