Hi Jim, thanks for replying :) >> >> $word_list{$_} = 0; > > If you assign 1 to the hash value, you can dispense with the 'exists' in > your test, below. >> #Here, using a hash looks much cleaner than iterating through an array >> push(@all_combinations, $temp_word) if (exists $word_list{$temp_word}); > > Here, if hash values are 1, you don't need 'exists': > > push(@all_combinations, $temp_word) if $word_list{$temp_word}; > >> }
I did not know this, I presume this is because 1 is not false? > You can use the built-in grep function to compare each of the words in your > word list to your specified pattern, used as a regular expression, and > return all that match. In that case, the period is fine, as it will match > any character: > > my @matches = grep( /^$temp_word$/i, @word_list ); > push( @all_combinations, @matches ); I had started using an array to hold my word list, but switched to hash as I thought it would be more efficient, certainly cleaner in code. When I think about it the hash lookup must be iterating over each element in the hash until it finds a match, whereas I suppose grep searches the whole array? (sorry, I've used command line grep lots, but never really in Perl) My list of words is 339231words long... I shall change from a hash to an array and use grep, or looking into it I may use List::MoreUtils as it has a "first_value" sub which should make it somewhat more efficient. Thanks for your advice, Ben