title: How do options behave in Perl's Getopt::Long?
body: <p>I have following piece of code that I am trying to understand:</p>
  
  <pre><code>use Getopt::Long;
  
  my $isheader ;
  
  if( !GetOptions(
  
      "is-header!"               =&gt; \$isheader,
  
    ) ) { exit 1; }
  
  print "isheader is = $isheader\n" ;
  </code></pre>
  
  <p>When I run the code as:</p>
  
  <pre><code>script.pl  --is-header
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>isheader is = 1
  </code></pre>
  
  <p>I have put a "!" at the end of option name is-header to negate so shouldn't output be:</p>
  
  <pre><code>isheader is = 0 
  </code></pre>
  
  <p>Secondly, if I run the script as:</p>
  
  <pre><code>script.pl --is 
  </code></pre>
  
  <p>It is still able to print</p>
  
  <pre><code>isheader is = 1
  </code></pre>
  
  <p>So I guess Perl expands partial names of the options?</p>
  
  <p>Thirdly, I run </p>
  
  <pre><code>script.pl --is-header --is-head 
  </code></pre>
  
  <p>Why does it not fail with ambiguous option error? It prints </p>
  
  <pre><code>isheader is = 1
  </code></pre>
  
  <p>Also if I replace  is-header! with is-header+  in the above code it still prints </p>
  
  <pre><code>isheader is = 1
  </code></pre>
  
  <p>while I guess it should print  isheader is = 2 , why so ?</p>
  
  <p>I read <code>https://perldoc.perl.org/Getopt/Long.html</code> and was experimenting with that to understand it, but seems like I am messing up.</p>