An alternate method, without external programs, using a method similar to the one seen in Perl's pearls:
#!/usr/bin/perl -w
use strict;
use DB_File;
my $search_word = shift
or die "word required";
my %sorted;
tie %sorted, 'DB_File', "words_jumble.db";
unless (keys %sorted) {
# Creates the word index.
open WORDS, "/usr/share/dict/words" # your favorite dictionary h
+ere
or die "can't open words file\n";
while (<WORDS>) {
chomp;
my $word = pack "C*", sort unpack "C*", lc $_;
$sorted{$word} .= "," if $sorted{$word};
$sorted{$word} .= $_;
}
close WORDS;
}
my $sorted_word = pack "C*", sort unpack "C*", lc $search_word;
die "$search_word not found\n" unless exists $sorted{$sorted_word};
print "[$_]\n" for split",", $sorted{$sorted_word};
__END__
perl jumble.pl elvis
[Elvis]
[evils]
[Levis]
[lives]
[veils]
perl jumble.pl parse
[pares]
[parse]
[pears]
[rapes]
[reaps]
[spare]
[spear]
perl jumble.pl steak
[Keats]
[skate]
[stake]
[steak]
[takes]