Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #7 from mariux64/add-nw-range
make numberofwords rangeable
  • Loading branch information
wwwutz committed Nov 28, 2022
2 parents 84895b0 + ddeff75 commit 0888cf9
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions chicken.pl
@@ -1,4 +1,5 @@
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use constant USAGE => <<'eof';
Expand All @@ -11,29 +12,44 @@

our %OPT;

my $opt_numberOfWords = 0;
my $opt_enumerate = 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=i' => \$opt_numberOfWords,
'numberofwords|nw=s' => \$opt_numberOfWordsRange,
'enumerate|en=i' => \$opt_enumerate,
) or die USAGE;

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

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

my @PARAGRAPH_SIZES = ( 15, 30, 75 );
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) {

if ( $opt_numberOfWords >= 0 ) {
$numberOfWords = $opt_numberOfWords;
}
else {
$numberOfWords = $PARAGRAPH_SIZES[ int( rand( scalar @PARAGRAPH_SIZES ) ) ];
$numberOfWords = int( rand( abs( $f - $t ) + 1 ) + ( ( $f < $t ) ? $f : $t ) );
}

# generate paragraph, with random words, capitalization, and punctuation.
Expand Down

0 comments on commit 0888cf9

Please sign in to comment.