#!/usr/bin/perl -w use strict; use Benchmark; sub mem { system("ps", "alx", $$); } mem(); print "adding words to the hash...\n"; my $time_start = new Benchmark; open DICT, "/usr/dict/words" or die "opening dict: $!"; my %h; my $n_words = 0; while (my $word = ) { ++$n_words; chomp $word; my $key = join "", sort split //, $word; push @{$h{$key}}, $word; } print "at end of file, tell returns: ", tell(DICT), "\n"; close DICT or die "closing dict: $!"; my $time_end = new Benchmark; print "done adding $n_words words.\n"; print "timing: ", timestr(timediff($time_end, $time_start)), "\n"; mem(); my @jumbles = qw(drol rach earth); print "\n"; local $" = ", "; foreach my $j (@jumbles) { my $k = join "", sort split //, $j; my @matches = @{$h{$k}}; print "for jumble \"$j\", key is \"$k\", matching words are: [@matches]\n"; } exit 0;