Skip to content
Permalink
b117b7c2c9
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 113 lines (83 sloc) 3.16 KB
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my $VERSION = '5.0';
sub USAGE {
print <<"eof";
usage: $0 [options]
--numberofwords -nw <n[-m]> : number of words, ranged from n to m
--enumerate -en <n> : create a list of arguments
--printchickenversion : print out "$VERSION"
eof
exit;
}
our %OPT;
my $opt_version = 0;
my $opt_numberOfWords = -1;
my $opt_numberOfWordsRange = '15-75';
my $opt_numberOfWordsRangeStart = 0;
my $numberOfWords = 0;
my ( $f, $t ) = ( 0, 0 );
my $opt_enumerate = 0;
GetOptions(
'numberofwords|nw=s' => \$opt_numberOfWordsRange,
'enumerate|en=i' => \$opt_enumerate,
'printchickenversion' => \$opt_version,
) or USAGE;
if ($opt_version) {
print $VERSION. "\n";
exit;
}
my @WORDS = ( "puk", "pukaak", "cluck", "cluckity", "bwak", "waak", "bok", "bwok", "cluck-a-buh-gawk", "cock-a-doodle-doo", "bwwwaak", "gobble", "honk" );
my @PUNCTUATIONS = ( ".", "...", "!", "?" );
if ( $opt_numberOfWordsRange =~ m/^\d+$/ ) {
$opt_numberOfWords = $opt_numberOfWordsRange;
}
elsif ( $opt_numberOfWordsRange =~ m/^\d+-\d+$/ ) {
( $f, $t ) = split( /-/, $opt_numberOfWordsRange, 2 );
}
else {
print STDERR "wrong format for --numberofwords\n";
print STDERR "should be either 'n' or 'n-m'. ( '-nw 50' or '-nw 30-90''\n";
exit;
}
my $enumerate = ($opt_enumerate) ? $opt_enumerate : 1;
for ( my $e = 0; $e < $enumerate; $e++ ) {
if ( $opt_numberOfWords >= 0 ) {
$numberOfWords = $opt_numberOfWords;
}
else {
$numberOfWords = int( rand( abs( $f - $t ) + 1 ) + ( ( $f < $t ) ? $f : $t ) );
}
# generate paragraph, with random words, capitalization, and punctuation.
my $paragraph = "";
my $previousWordHadPunctuation = 0;
for ( my $i = 0; $i < $numberOfWords; $i++ ) {
# pick a random word
my $word = $WORDS[ int( rand( scalar @WORDS ) ) ];
# magic multiplier
$word = join( "-", ($word) x ( 4 - int( ( log( rand(7) + 1 ) / log(2) ) + 1 ) ) );
# even more magical multiplier
$word =~ s/([aou]){2,}?/$1 x (rand(7)+1)/ge;
# optionally add punctuation
# note: always add punctuation if it's the last word.
my $shouldAddPunctuation = $i == $numberOfWords - 1 || rand() > 0.9;
my $punctuation = $shouldAddPunctuation ? $PUNCTUATIONS[ int( rand( scalar @PUNCTUATIONS ) ) ] : "";
$word = $word . $punctuation;
# optionally capitalize the word
# note: always capitalize if it's the first words, or if preceded by punctuation
my $shouldCapitalize = $i == 0 || $previousWordHadPunctuation || rand() > 0.7;
$word = $shouldCapitalize ? uc( substr( $word, 0, 1 ) ) . substr( $word, 1 ) : $word;
# preserve info for next iteration
$previousWordHadPunctuation = $shouldAddPunctuation;
# add word to paragraph
$paragraph = $paragraph . $word;
# if not last one, add a space
$paragraph = $i == $numberOfWords - 1 ? $paragraph : $paragraph . " ";
}
if ($opt_enumerate) {
printf "%d. ", $e + 1;
}
print $paragraph;
print "\n";
}