Skip to content

Commit

Permalink
chicken: add numberofwords option
Browse files Browse the repository at this point in the history
Waaak... Bwak gobble-gobble cluckity cluck-a-buh-gawk cluck Bok bwak
cluckity cluck-cluck-cluck cluck Gobble-gobble cluck-cluck-cluck...
Bwak cock-a-doodle-doo bok Cluck-cluck-cluck! Cluckity Bwok
cluck-a-buh-gawk puk bok Gobble-gobble Cluck-a-buh-gawk
cluck-a-buh-gawk bwwwaaaaaaaaaak bwak waaak bwak puk puk bwak!
  • Loading branch information
wwwutz committed Nov 22, 2022
1 parent 6553ae2 commit f1efe95
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions chicken.pl
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/usr/bin/perl -w
use Getopt::Long;
use constant USAGE => <<'eof';
usage: $0 [options]
--numberofwords --nw : number of words
eof

our %OPT;

my $numberOfWords = 0;

GetOptions( 'numberofwords|nw=i' => \$numberOfWords, ) or die USAGE;

my @WORDS = (
"puk", "pukaaak", "cluck", "cluck-cluck-cluck", "cluckity", "bwak",
Expand All @@ -10,7 +24,9 @@

my @PARAGRAPH_SIZES = ( 15, 30, 75 );

my $numberOfWords = $PARAGRAPH_SIZES[ int( rand($#PARAGRAPH_SIZES) ) ];
unless ($numberOfWords) {
$numberOfWords = $PARAGRAPH_SIZES[ int( rand($#PARAGRAPH_SIZES) ) ];
}

# generate paragraph, with random words, capitalization, and punctuation.
my $paragraph = "";
Expand All @@ -34,7 +50,7 @@
# 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;
$word = $shouldCapitalize ? uc( substr( $word, 0, 1 ) ) . substr( $word, 1 ) : $word;

# preserve info for next iteration
$previousWordHadPunctuation = $shouldAddPunctuation;
Expand Down

0 comments on commit f1efe95

Please sign in to comment.