#!/usr/bin/perl use strict; my $dloc = '/usr/share/dict/words'; my @fibo = (0, 0); my $message = lc(join ' ', @ARGV); my @message = split /([.!?]?\s*)/, $message; my @out; my $new_sentence = 1; my $lffl = 'a'; my %words; open (DICT, "<$dloc") or die "no dictionary at $dloc"; sub get_new_word { my ($target_letter, $target_number) = @_; $target_number ||= 1; # seeds our fibonacci sequence my $sought = 0; my $found = 0; my $candidate; my $n; while (not $found) { $candidate = ; unless ($candidate) { die "never found word for $target_letter at $target_number" if $sought; $sought = 1; seek(DICT, 0, 0) or die "um. no seeky."; next; } chomp($candidate); next if ( (length($candidate) < 3) or ((not $sought) and ($candidate lt $lffl)) or ($candidate =~ /[A-Z]/) or (defined $words{$candidate}) ); $n = (($target_number-1) % length($candidate)); $found++ if ( ( substr($candidate,$n,1) eq $target_letter) # and ( print "(pass $sought): $candidate ? ('y' to accept)" # and ( =~ /^y/i)) ); } $lffl = chr(ord($candidate)+length($candidate)); $words{$candidate} = 1; return ($candidate, ($n+1)); } for my $letter (@message) { if ($letter =~ m/[.!?]/) { push @out, $letter . "\n "; $new_sentence = 1; } elsif (($letter =~ m/\s+/) and @out) { push @out, '. '; $new_sentence = 1; } elsif ($letter =~ m/[a-zA-Z]/) { my ($outword, $newf) = get_new_word($letter, $fibo[-2]+$fibo[-1]); if ($new_sentence) { $outword = ucfirst($outword); $new_sentence = 0; } push @out, ' '.$outword; @fibo = ($fibo[-1], $newf); } } print join '', "\n ",@out,"\n\n";