#!/usr/bin/perl use warnings; use strict; use Getopt::Long; use Pod::Usage; my $Action; # Will be one of: add, edit, list, view my $Value; # Will be the value of the =s part of the option sub set_action { pod2usage( -message => 'Must use only one of --add, --edit, --list, or --view', ) if defined $Action; $Action = shift; $Value = shift; } GetOptions( 'add|a=s' => \&set_action, 'edit|e=s' => \&set_action, 'list|l=s' => \&set_action, 'view|v=s' => \&set_action, 'man|m' => sub { pod2usage(-exitstatus => 0, -verbose => 2) }, 'help|h|?' => sub { pod2usage(1) }, ) or pod2usage(2); # Update2: Changed back to pod2usage(2) from exit(2) (see below) pod2usage( -message => 'Must use at least one of --add, --edit, --list, or --view', -exitval => 1, ) unless defined $Action; # Run program { add => \&add_record, edit => \&edit_record, list => \&list_record, view => \&view_record, }->{$Action}->($Value); sub add_record { my $record = shift; print "Adding record $record.\n"; } sub edit_record { my $record = shift; print "Editing record $record.\n"; } sub list_record { my $record = shift; print "Listing record $record.\n"; } sub view_record { my $record = shift; print "Viewing record $record.\n"; } =head1 NAME Program Name - description =head1 SYNOPSIS program [--man] [--help] --add|--edit|--list|--view RECORD -a, --add RECORD Add a record -e, --edit RECORD Edit a record -l, --list RECORD List record(s) -v, --view RECORD View a record -h, -?, --help Display this help screen -m, --man Display the program's manual Note, you must include one (and only one) of add, edit, list, or view. =head1 DESCRIPTION Detailed program description. =head1 AUTHOR The Author =cut