>>>>> "BL" == Ben Lavery <[email protected]> writes:
BL> use warnings;
BL> use strict;
good!
BL> use Math::Combinatorics;
BL> #Read list of valid words into hash
BL> my $WORDFILE='Words';
BL> open(WORDFILE, "$WORDFILE") or die "can't open $WORDFILE: $!";
BL> while (<WORDFILE>) {
BL> chomp;
BL> $word_list{$_} = 0;
BL> }
BL> close(WORDFILE);
don't use glob filehandles. use lexical file handles. or this is even
easier and faster:
use File::Slurp ;
my %word_list = map { chomp; ( $_ => 1 ) } read_file( $WORDFILE ) ;
done!
BL> #Here, using a hash looks much cleaner than iterating
through an array
hashes are almost always better for token lookups than scanning
arrays. don't doubt yourself in this area.
BL> push(@all_combinations, $temp_word) if (exists
$word_list{$temp_word});
BL> #Remove duplicates
BL> my %hash =
BL> @all_combinations = keys %hash;
you can merge those:
my @all_combinations = keys %{ map { $_ => 1 } @all_combinations } ;
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/