The Perl module IO::Prompt::Tiny is useful for prompting with a prompt message, accepting input portably, or accepting default values if it detects a non-interactive runtime.
Combine this with Getopt::Long to accept command line inputs.
Your program might check for the definedness of the Getopt::Long options, and for each one that hasn't been supplied on the command line, invoke prompt()
.
Usage info and documentation are made trivial by the Perl module Pod::Usage.
Here's an example:
use strict;
use warnings;
use IO::Prompt::Tiny 'prompt';
use Pod::Usage;
use Getopt::Long;
my( $age, $sex, $blah, $help, $man );
GetOptions(
'age=s' => \$age,
'sex=s' => \$sex,
'blah=s' => \$blah,
'help|?' => \$help,
'man' => \$man,
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;
$age //= prompt( 'Enter age: ', '0' );
$sex //= prompt( 'Enter sex: ', 'undeclared' );
$blah //= prompt( 'Blab now: ', '' );
print "Your age was entered as <$age>, sex declared as <$sex>, and you ",
"chose to blab about <$blah>.\n";
__END__
=head1 User Input Test
sample.pl - Using Getopt::Long, Pod::Usage, and IO::Prompt::Tiny
=head1 SYNOPSIS
sample.pl [options]
Options:
-help Brief help message.
-age n Specify age.
-sex s Specify sex.
-blah blah Blab away.
=head1 INTERACTIVE MODE
If C<-age>, C<-sex>, and C<-blah> are not supplied on the command line, the
user will be prompted interactively for missing parameters.
=cut
Getopt::Long and Pod::Usage are core Perl modules; they ship with every Perl distribution, so you should already have them. IO::Prompt::Tiny is on CPAN, and although it has a few non-core build dependencies, its runtime dependencies are core-only, and pretty light-weight.