How to use GetOptions utility to handle 'optional' command-line arguments in Perl? -


there many perl tutorials explaining how use getoptions utility process command-line arguments expected, else exit appropriate message.

in requirement have following optional command-line arguments, like,

  • -z zip_dir_path : zip output
  • -h : show help.

i tried few combinations getoptions did not work me.
question is: how use getoptions handle requirement?

edit: -z needs 'zip directory path'

edit2: script has following compulsory command-line arguments:

  • -in input_dir_path : input directory
  • -out output_dir_path : output directory

here's code:

my %args; getoptions(\%args, "in=s", "out=s" ) or die &usage();  die "missing -in!" unless $args{in}; die "missing -out!" unless $args{out}; 

hope edit adds more clarity.

a : (colon) can used indicate optional options:

#!/usr/bin/env perl  use strict; use warnings;  use getopt::long;  ( $zip, $help, $input_dir, $output_dir );  getoptions(     'z:s'   => \$zip,     'h'     => \$help,     'in=s'  => \$input_dir,     'out=s' => \$output_dir, ); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -