Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Check array for several matches

by Marshall (Canon)
on May 13, 2017 at 00:00 UTC ( [id://1190171]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Check array for several matches
in thread Check array for several matches

Yes, this will certainly work! I made an implicit assumption that there were very few check words (perhaps just 3) to be checked against perhaps a potentially very big list of other words. So I restricted my hash to be only the 3 checked words instead of all_words. But I think your code is just fine.

I don't think it is necessary to beat this thing to death in all its variations. I don't know whether I actually succeeded or not, but I was attempting to address the OP's comments about searching the internet for hours and copying code that he didn't understand and that didn't work for him.

I avoided map{} and grep{} (which are special kinds of foreach loops) and attempted to write very simple loops in the hope that the OP will take the time to understand them. I added a whole lot of verbiage in an attempt to explain an example of the algorithmic thought process. I am hoping that the OP learned not only a solution to this current problem, but also stuff that is helpful to future problems.

Replies are listed 'Best First'.
Re^4: Check array for several matches
by Lotus1 (Vicar) on May 13, 2017 at 00:24 UTC

    The short circuit thing doesn't add much for three items, that's true. Probably isn't a noticeable difference for anything less than 3,000 really. I had already written mine up before I noticed yours so it seemed fitting to put it with yours.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found