#!/usr/bin/perl use strict; use Data::Dumper; # Grab all the words from the file use vars qw( @words %dict ); open(IN, "word.lst") or die "Error: $!\n"; print "Reading wordlist...\n"; while() { chomp $_; push @words, $_; } # Build a content-dictionary. Each entry, a-z, has a set of words which contain # that letter. print "Building dictionary...\n"; foreach my $word (@words) { my @chars = split //, $word; my %chars; foreach my $char (@chars) { $chars{$char} = 1; } foreach my $char (keys %chars) { push @{$dict{$char}}, $word; } } sub next_char { my $char = shift; my $val = ord($char); return chr($val++); } # Build a sentence containing all 26 letters sub base_sentence { my $location = shift; my %used; my $sentence; foreach my $char ('a' .. 'z') { unless($used{$char}) { my $word = $dict{$char}->[$location->{$char}]; if($word eq '') { my $char2 = next_char($char); $location->{$char2}++; $location->{$char} = 0; $word = $dict{$char}->[$location->{$char}]; } else { # $location->{$char}++; } $sentence .= ' ' . $word; my @chars = split //, $word; foreach my $char (@chars) { $used{$char}++; } } } return [$sentence, $location]; } #print "Generating a base sentence...\n"; print "Generating lots of things...\n"; my $location; while(1) { my $sent = base_sentence($location); my $sentence = $sent->[0]; $location = $sent->[1]; $location->{a}++; print "$sentence\n\n"; }