Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: off-by-one string comparison

by Zaxo (Archbishop)
on Jun 05, 2005 at 17:42 UTC ( [id://463740]=note: print w/replies, xml ) Need Help??


in reply to off-by-one string comparison

Text::Levenshtein implements a well-known metric for difference between strings.

$ perl -MText::Levenshtein=distance -e'print distance( "foo bar baz"," +fooo bar baz"),$/' 1 $

So your off-by-one test could be written,

use Text::Levenshtein qw/distance/; sub off_by_one { 1 == distance("foo bar baz", shift); }
For extra credit, leave out the "1 ==" part ;-)

After Compline,
Zaxo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found