I have a hard time thinking about Getopt::Long without also invoking Pod::Usage. And being an old sysadmin type, I like my documentation at the top of my programs, even if it costs me a millisecond of compile time.

#!/usr/bin/perl use warnings; use strict; =head1 NAME param-example.pl - An example of how to use command line parms and ge +topts concurrently. =head1 SYNOPSIS param-example.pl [-u username] [-p password] [username] [password] Options: -help brief help message -man full documentation -user use name -password password =head1 VERSION author dwm042 date 10/6/2007 modified N/A =head1 DESCRIPTION param-example.pl - An example of how to use command line parms and ge +topts concurrently. This program looks first for command line parameters to define username and password and then looks for flags to define the username and password. =cut use Getopt::Long; use Pod::Usage; my $help = 0; my $man = 0; my $user = 0; my $passwd = 0; GetOptions( 'help|?' => \$help, man => \$man, "user=s" => \$user, "passwd=s" => \$passwd, ) or pod2usage(2); pod2usage( -exitval => 0, -verbose => 1 ) if $help; pod2usage( -exitval => 0, -verbose => 2 ) if $man; my $username = shift; my $password = shift; $username = $user unless defined($username); $password = $passwd unless defined($password); pod2usage(1) unless $username; pod2usage(1) unless $password;

In reply to Re: How Do I Use Getopt::Long without switches? by dwm042
in thread How Do I Use Getopt::Long without switches? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.