From 50c8927784031c2d180b820e02fd1a0508de721d Mon Sep 17 00:00:00 2001 From: Peter Marquardt Date: Tue, 22 Nov 2022 09:13:06 +0100 Subject: [PATCH] chicken.pl: BANG --- chicken.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 chicken.pl diff --git a/chicken.pl b/chicken.pl new file mode 100755 index 0000000..b949ad6 --- /dev/null +++ b/chicken.pl @@ -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"; +