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

Re^2: Comparing Lines within a Word List

by dominick_t (Acolyte)
on Apr 27, 2016 at 04:59 UTC ( [id://1161611]=note: print w/replies, xml ) Need Help??


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

Thank you for the reply! The text file contains one word per line, and no words in the file repeated. You could basically think of the text file as a dictionary of standard English words. Ideally the user would be able to easily supply any letter pair each execution. I figured it would be easier for me just to see some code that will do the trick for the R/S pairing, and then I assumed it would be easy enough matter to add some lines that would allow the user to input any pair whatsoever.
  • Comment on Re^2: Comparing Lines within a Word List

Replies are listed 'Best First'.
Re^3: Comparing Lines within a Word List
by GotToBTru (Prior) on Apr 27, 2016 at 12:27 UTC

    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://1161611]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found