in reply to Attempting to fill a hash
% cat AnagramWordList foo bar baz % cat 690557.pl #!/usr/bin/env perl use strict; use warnings; my $wordfile = 'AnagramWordList'; my %hashlist; ### It is a good practice to use the 3-argument form of "open" open my $wordhandle, '<', $wordfile or die "Unable to open WordList: $ +!"; while (<$wordhandle>) { chomp; ### Remove newline character $hashlist{$_}++; ### Add word to hash } close $wordhandle; ### It is a good practice to close the file AS +AP ### Print out contents of hash while (my ($key, $value) = each %hashlist) { print "key=$key, value=$value\n"; } % ./690557.pl key=bar, value=1 key=baz, value=1 key=foo, value=1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Attempting to fill a hash
by TwistedTransistor (Novice) on Jun 06, 2008 at 01:51 UTC | |
by almut (Canon) on Jun 06, 2008 at 02:09 UTC | |
by chrism01 (Friar) on Jun 06, 2008 at 05:22 UTC | |
by TwistedTransistor (Novice) on Jun 06, 2008 at 02:23 UTC |