Syntactic Confectionery Delight | |
PerlMonks |
Re: Words in Wordsby ww (Archbishop) |
on Sep 30, 2011 at 19:29 UTC ( [id://928901]=note: print w/replies, xml ) | Need Help?? |
Re Line 23, you MAY speed things up a little by reading $wordfile directly into a hash. Searching Google for site:PerlMonks.org +Perl +'file to hash' produces some relevant results in prior discussions here in the Monastery. Strike the site specification and you'll find some other sources (albeit, of unknown reliability). Even with a wordlist of the size you're using, that runtime seems far to the high-side. Is the box upon which you're writing this reasonably current (fast?) and what version of Perl are you using? Counting the first para above, you now have three reasonable alternatives (update: and one very reasonable question about the precision of your spec </update>) ... so the rest of this node will focus on some nits. Line 4 seems to reflect a view that $datapath and $wordfile are constants. While you're using them within the scope of the conventional meaning of "constant," they aren't in the sense of allowing the compiler to optomize. Lines 9 and 10 declare global variables... not, IMO, as major problem here, but in more complex programs, it's wise to declare them in such a way as to minimize their scope (for more on this, try perldoc -q scope at your CLI). Your comment at Line 26 reflect what is actually ( IMO, usually [...additional qualifiers may be required] ) a better (if not "best") practice. The more complex you make your regex, the more opportunities you'll have to obscure a logic problem and/or to create something that sets the regex engine thrashing.
In Section
Seekers of Perl Wisdom
|
|