Okay.. I was bored and wanted to write some stupid script that made use of the dictionary file. I also really suck at crossword puzzles. So I came up with this little script to help me out.
#!/usr/local/bin/perl -w use strict; my $word_file = '/usr/share/dict/words'; my @words = (); my $word_length; my @tests; if (@ARGV == 2) { $word_length = shift; my $tests = shift; @tests = split /,/,$tests; print "\$word_length = $word_length\n"; print "\@tests = @tests\n\n"; }elsif (@ARGV ==1) { $word_length = shift; print "\$word_length = $word_length\n"; }else { die "usage: $0 word_len [test1],[test2] etc..\n", " $0 word_len\n\n", "example: $0 3 [1=a],[3=s]\n", " find 3 letter word starts with 'a' ends with 's'\n\n", " $0 14\n", " find 14 letter word.\n\n"; } open (INP, $word_file) or die "Error opening word database: [$word_fil +e] $!\n"; while (<INP>){ chomp; push @{$words[length]}, lc; } close (INP); my @chk = get_words($word_length); die "No Words that long.\n" unless @chk; foreach my $word (@chk) { if (@tests) { print "$word\n" if check_word($word,@tests); }else{ print "$word\n" } } sub check_word { my $word = shift; my @tests = @_; my @letters = split //, $word; foreach my $test (@tests){ my ($num,$let) = $test =~ /^\[(\d+)=(\w)\]$/; --$num; return unless $letters[$num] eq $let; } return 1; } sub get_words { my $len = shift; return @{$words[$len]} if exists $words[$len]; return; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Crossword helper
by epoptai (Curate) on Jan 27, 2001 at 15:30 UTC | |
Alternative invocation
by orkysoft (Friar) on Jan 28, 2001 at 07:09 UTC | |
by Anonymous Monk on Jan 29, 2001 at 01:24 UTC | |
by orkysoft (Friar) on Jan 29, 2001 at 04:29 UTC | |
Re: Crossword helper
by Anonymous Monk on Jan 28, 2001 at 01:20 UTC | |
by tye (Sage) on Jan 28, 2001 at 05:28 UTC | |
by Anonymous Monk on Jan 28, 2001 at 07:38 UTC | |
Re: Crossword helper
by chipmunk (Parson) on Jan 30, 2001 at 23:52 UTC | |
by zzspectrez (Hermit) on Jan 31, 2001 at 06:01 UTC |