Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: How i can use getopt in my script?

by karlgoethebier (Monsignor)
on Apr 25, 2014 at 09:12 UTC ( #1083762=note: print w/replies, xml ) Need Help??

in reply to How i can use getopt in my script?

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 =head1 SYNOPSIS ./ [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 ./ -a foo -d bar =head1 BUGS None. =head1 AUTHOR Karl Goethebier =cut

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083762]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-04-24 00:20 GMT
Find Nodes?
    Voting Booth?