diff --git a/chicken.pl b/chicken.pl index ce6036d..39faf97 100755 --- a/chicken.pl +++ b/chicken.pl @@ -4,15 +4,20 @@ usage: $0 [options] - --numberofwords --nw : number of words + --numberofwords -nw : number of words + --enumerate -en : create a list of arguments eof our %OPT; -my $numberOfWords = 0; +my $opt_numberOfWords = 0; +my $opt_enumerate = 0; -GetOptions( 'numberofwords|nw=i' => \$numberOfWords, ) or die USAGE; +GetOptions( + 'numberofwords|nw=i' => \$opt_numberOfWords, + 'enumerate|en=i' => \$opt_enumerate, +) or die USAGE; my @WORDS = ( "puk", "pukaaak", "cluck", "cluck-cluck-cluck", "cluckity", "bwak", @@ -24,44 +29,52 @@ my @PARAGRAPH_SIZES = ( 15, 30, 75 ); -unless ($numberOfWords) { - $numberOfWords = $PARAGRAPH_SIZES[ int( rand($#PARAGRAPH_SIZES) ) ]; -} - -# generate paragraph, with random words, capitalization, and punctuation. -my $paragraph = ""; +my $enumerate = ($opt_enumerate) ? $opt_enumerate : 1; -my $previousWordHadPunctuation = 0; +for ( my $e = 0; $e < $enumerate; $e++ ) { + if ($opt_numberOfWords) { + $numberOfWords = $opt_numberOfWords; + } + else { + $numberOfWords = $PARAGRAPH_SIZES[ int( rand( scalar @PARAGRAPH_SIZES ) ) ]; + } -for ( my $i = 0; $i < $numberOfWords; $i++ ) { + # generate paragraph, with random words, capitalization, and punctuation. + my $paragraph = ""; + my $previousWordHadPunctuation = 0; + for ( my $i = 0; $i < $numberOfWords; $i++ ) { - # pick a random word + # pick a random word - my $word = $WORDS[ int( rand($#WORDS) ) ]; + my $word = $WORDS[ int( rand( scalar @WORDS ) ) ]; - # optionally add punctuation - # note: always add punctuation if it's the last word. + # 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; + 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; + # 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; + $word = $shouldCapitalize ? uc( substr( $word, 0, 1 ) ) . substr( $word, 1 ) : $word; - # preserve info for next iteration - $previousWordHadPunctuation = $shouldAddPunctuation; + # preserve info for next iteration + $previousWordHadPunctuation = $shouldAddPunctuation; - # add word to paragraph - $paragraph = $paragraph . $word; + # add word to paragraph + $paragraph = $paragraph . $word; - # if not last one, add a space - $paragraph = $i == $numberOfWords - 1 ? $paragraph : $paragraph . " "; -} + # if not last one, add a space + $paragraph = $i == $numberOfWords - 1 ? $paragraph : $paragraph . " "; + } -print $paragraph; -print "\n"; + if ($opt_enumerate) { + printf "%d. ", $e + 1; + } + print $paragraph; + print "\n"; +}