Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: improving the efficiency of a scriptby Zaxo (Archbishop) |
on Jun 18, 2006 at 16:48 UTC ( [id://556124]=note: print w/replies, xml ) | Need Help?? |
If this is going to be used a lot, I'd either stuff the dictionary file into a database, or else construct an index to the offsets and sizes of initial letter sections of the dictionary file. Assuming the dictionary file is alphabetically sorted, you don't need to slurp the whole file into an array. That is a large chunk of memory for a million words. Allocations that size will slow you painfully if you are driven into swap. Try just building an array with the a's, shuffling, and taking the first hundred elements. Then discard the a's and replace with the b's, all in a while loop that only reads one line at a time. You don't need a loop to pick the first hundred elements of an array. A slice will do, and is much faster. After Compline,
In Section
Seekers of Perl Wisdom
|
|