#!/usr/bin/perl -w use strict; sub cls { system $^O =~ /win32/i ? 'cls' : 'clear' } sub load_dict { my $path = shift; cls(); print "Loading the dictionary..."; open my $dict, $path or die "Dictionary not found at '$path'\n"; chomp( my @words = <$dict> ); close $dict; print " Done.\n", scalar(@words), " words in the dictionary.\n";; sleep 3; return \@words; } my $path = $ARGV[0] or die qq{Usage: "perl }, $0=~m#.*[/\\](.*)$#, qq{ path_to_dictionary"\n}; my $words = load_dict( $path ); for (;;) { my @found; cls(); print 'Letters to unscramble: '; chomp( my $letters = ); last unless $letters; for my $len (reverse( 3 .. length $letters )) { my $s = join '?', (sort( split //, $letters ), ''); for my $word (@$words) { next unless length $word == $len; my $t = join '', sort (split //, $word); push @found, $word if $t =~ /^$s$/; } } print "\n", scalar(@found), " words found in '$letters':\n"; print " - $_\n" for @found; print "\nPress enter to start new scramble...\n"; ; }