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; }

In reply to Crossword helper by zzspectrez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.