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;
}
}
Hope that is what you expected ...
C:\> x.pl x.txt
cat = nice animal
snake = nasty animal
dog = best friend
cat/nice animal
dog/best friend
snake/nasty animal
|