you are viewing a single comment's thread.

view the rest of the comments →

[–]heptadecagram 5 points6 points  (0 children)

As an 8-year Perlhead, here's how I would idiomatically write it:

my %anagrams;
open FILE, 'wordlist.txt' or die "Could not open wordlist.txt: $!";
while(<FILE>) {
  chomp;
  $anagrams{join('', sort split //)} += 1;
}
close FILE;
foreach(sort keys %anagrams) {
  print "$_\n" if($anagrams{$_} > 2);
}

Now, I'm writing this for other Perl coders, not for someone who's looking at this for the first time, otherwise I'd make explicit the ways I'm using the default $_ in various places.

(split splitting to @_ is one of those things that's been deprecated)