in reply to hash array
Hope that is what you expected ...my %dictionary; readWords(\%dictionary); sortDictionary(\%dictionary); sub readWords { $numWords = 0; open FILE, $ARGV[0] or die $!; while (my $lines = <FILE>) { $numWords++; chomp $lines; my ($words, $definitions) = split('/', $lines); $words = lc($words); $dictionary{$words} = $definitions; } foreach $words (keys(%dictionary)) { print "$words = ",$dictionary{$words},"\n"; } close FILE; } sub sortDictionary { foreach my $key (sort keys %dictionary) { $key =~ /^(.)/; my $line = $key . '/' . $dictionary{$key} . "\n"; print $line; } }
C:\> x.pl x.txt cat = nice animal snake = nasty animal dog = best friend cat/nice animal dog/best friend snake/nasty animal
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash array
by borovez (Initiate) on Mar 11, 2012 at 23:20 UTC |