After studying up a bit on defined, finally figured out what to do. Here is the code
#!/usr/bin/perl
use strict;
use warnings;
my $baz = 0;
my $foo = shift;
$foo = 1 if !defined($foo);
chomp(my @bar = qw( etc etcetera ));
die if $foo < 1;
while($baz < $foo){
$baz += 1;
print "$bar[rand @bar] ", "ad infinitum\n";
}
It returns a single result if nothing is entered at command line, and it returns error message if you select 0 or less at the command line. It works properly in every other respect as well.
Thanks, Perlmonks! |