Skip to content

Commit

Permalink
chicken.pl: BANG
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwutz committed Nov 22, 2022
0 parents commit 50c8927
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions chicken.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/perl -w

my @WORDS = (
"puk", "pukaaak", "cluck", "cluck-cluck-cluck", "cluckity", "bwak",
"waaak", "bok", "bwok", "cluck-a-buh-gawk", "cock-a-doodle-doo", "bwwwaaaaaaaaaak",
"gobble-gobble", "honk",
);

my @PUNCTUATIONS = ( ".", "...", "!", "?" );

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

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

# 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($#WORDS) ) ];

# 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($#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 . " ";
}

print $paragraph;
print "\n";

0 comments on commit 50c8927

Please sign in to comment.