title: How to use GetOptions utility to handle 'optional' command-line arguments in Perl?
body: <p>There are many Perl tutorials explaining how to use GetOptions utility to process only the command-line arguments which are expected, else exit with an appropriate message.</p>
  
  <p>In my requirement I have following optional command-line arguments, like, </p>
  
  <ul>
  <li>-z  zip_dir_path : zip the output</li>
  <li>-h : show help.  </li>
  </ul>
  
  <p>I tried few combinations with GetOptions which did not work for me.<br>
  So my question is: How to use GetOptions to handle this requirement? </p>
  
  <p>EDIT: -z needs 'zip directory path' </p>
  
  <p>EDIT2:
  My script has following compulsory command-line arguments:</p>
  
  <ul>
  <li>-in   input_dir_path : Input directory</li>
  <li>-out   output_dir_path : Output directory</li>
  </ul>
  
  <p>Here's my code:</p>
  
  <pre><code>my %args;
  GetOptions(\%args,
  "in=s",
  "out=s"
  ) or die &amp;usage();
  
  die "Missing -in!" unless $args{in};
  die "Missing -out!" unless $args{out};
  </code></pre>
  
  <p>Hope this EDIT adds more clarity.</p>