[Linux-disciples] Converting an array to a hash

Stephen R Laniel steve at laniels.org
Wed Oct 6 12:18:23 EDT 2004


I'd like to read in a file in Perl, then take all the
English words in that file (as opposed to Perl-regex words)
and load them into a big hash. The quickest way I can think
of to do this is something like

my %wordsHash = ();
my $infile = join '', <>;
my @words = ($infile =~ m/([A-Za-z]+)/g);
foreach my $word (@words) {
	$wordsHash{$word} = 1;
}

but that's creating an arry (@words) that I don't really
need. Is there any way to read the words directly into the
hash?

-- 
``I am all about the delivery of *justice* to
  parking, people. That is all.''
 -Jon Sung, 27 September 2004



More information about the Linux-disciples mailing list