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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |