Take a look at Getopt::Long and Pod::Usage.

I do it like this:

Update: Bad copy & paste. Added handling of help option...

#!/usr/bin/env perl use strict; use warnings; use Getopt::Long; use Pod::Usage; use Data::Dump; my ( %options, $option ); Getopt::Long::Configure("no_ignore_case"); GetOptions( \%options, "help", "abc=s", "def=s" ); pod2usage( -exitstatus => 0, -verbose => 2 ) if $options{help}; # adde +d foreach $option ( $options{abc}, $options{def} ) { pod2usage( -exitstatus => 2, -verbose => 2 ) unless $option; } dd %options; # your code here... __END__ =pod =head1 NAME options.pl =head1 SYNOPSIS ./options.pl [options] =head1 OPTIONS =over 8 =item B<-h, --help> Prints a brief help message and exits. =item B<-a, --abc> Bla, bla. =item B<-d, --def> Bla, bla. =back =head1 DESCRIPTION It's just an example. =head1 USAGE ./options.pl -a foo -d bar =head1 BUGS None. =head1 AUTHOR Karl Goethebier =cut

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»


In reply to Re: How i can use getopt in my script? by karlgoethebier
in thread How i can use getopt in my script? by manan.patel

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.