in reply to Random word generator
Using this as a base, it's fairly trivial to generate random words. You can restrict the length with the built in length function.
Alternatively, there is always CPAN - Data::Random::WordList, for example. You could use that to generate the words, and again use length to throw away the ones that are not the right length.
Update: And for no other reason than I felt like it ;), here is a short snippet of code that demonstrates how one might do this (in this case, using shuffle() from List::Util):
#!/usr/bin/perl -l use strict; use warnings; use List::Util qw/shuffle/; my $wordlist = '/usr/share/dict/words'; my $length = 10; my $numwords = 10; my @words; open WORDS, '<', $wordlist or die "Cannot open $wordlist:$!"; while (my $word = <WORDS>) { chomp($word); push @words, $word if (length($word) == $length); } close WORDS; my @shuffled_words = shuffle(@words); print for @shuffled_words[0 .. 9];
Hope this helps,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Random word generator
by rooneyl (Sexton) on Feb 27, 2008 at 19:27 UTC |