Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How i can use getopt in my script?

by karlgoethebier (Curate)
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 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»


Comment on Re: How i can use getopt in my script?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083762]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-10-25 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls