#!/usr/bin/perl -w use strict; use Getopt::Std; my (%options); getopts("d:h", \%options); if ($options{h}) { print <<'eof'; -d file: dictionary file eof exit; } my ($sorted_word, %word, @most_ref); my ($number) = 0; my ($word_file) = $options{d} || "/usr/share/dict/words"; open(WORDS_FH, "<" . $word_file) or die ("Can't open $word_file: $!\n"); while () { chomp; $sorted_word = join '', sort split //, $_; push @{$word{length($sorted_word)}{$sorted_word}}, $_; } foreach my $length (keys %word) { foreach $sorted_word (keys %{$word{$length}}) { if ($number < $#{$word{$length}{$sorted_word}}+1) { $number = $#{$word{$length}{$sorted_word}}+1; @most_ref=(); push @most_ref, \@{$word{$length}{$sorted_word}}; } elsif ($number == $#{$word{$length}{$sorted_word}}+1) { push @most_ref, \@{$word{$length}{$sorted_word}}; } } } print $number . ":\n"; foreach my $word_ref (@most_ref) { foreach my $word (sort @{$word_ref}) { print " " x 2 . $word . "\n"; } print "\n"; } #### #!/usr/bin/perl -w use strict; use Getopt::Std; my (%options); getopts("d:h", \%options); if ($options{h}) { print <<'eof'; -d file: dictionary file eof exit; } my ($sorted_word, %word, @most_ref); my ($number) = 0; my ($word_file) = $options{d} || "/usr/share/dict/words"; open(WORDS_FH, "<" . $word_file) or die ("Can't open $word_file: $!\n"); while () { chomp; $sorted_word = join '', sort split //, $_; push @{$word{$sorted_word}}, $_; } foreach $sorted_word (keys %word) { if ($number < $#{$word{$sorted_word}}+1) { $number = $#{$word{$sorted_word}}+1; @most_ref=(); push @most_ref, \@{$word{$sorted_word}}; } elsif ($number == $#{$word{$sorted_word}}+1) { push @most_ref, \@{$word{$sorted_word}}; } } print $number . ":\n"; foreach my $word_ref (@most_ref) { foreach my $word (sort @{$word_ref}) { print " " x 2 . $word . "\n"; } print "\n"; }