Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Comparing Lines within a Word List

by GotToBTru (Prior)
on Apr 27, 2016 at 12:27 UTC ( [id://1161624]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Comparing Lines within a Word List
in thread Comparing Lines within a Word List

The Tutorials here will tell you everything you need to know about opening a file and reading the words therein. You will probably store them in an array. Here's a trick to detect when two words differ by only single letter:

if (($word1 ^ $word2) =~ tr[\1-\255][] == 1) { ... }

That works because the ^ operator performs an XOR function. Same letters in $word1 and $word2 become null values, and the tr function returns the count of how many matches it found. I told it to look for non-null values. If the count is 1, that's a word we want to look at.

Update: should have looked at the other replies before I composed this one. Better and more complete answers already provided!

But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2026-01-25 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (126 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.