title: Exit from the script if required arguments not found in Perl
body: <p>I have script which should take two arguments from command line. To achieve that, I am using <code>Getopt::Long</code> Perl module.</p>
  <p>Here is the script:</p>
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  
  use Getopt::Long 'HelpMessage';
  
  GetOptions(
    'node|n=s' =&gt; \my $node,
    'cmd|c=s'  =&gt; \my $command,
    'help'     =&gt;  sub { HelpMessage(0) }
  ) or HelpMessage(1);
  
  print &quot;Node:$node\nCmd:$command\n&quot;;
  
  doSomeOpearation($node, $command);
  
  print &quot;END\n&quot;;
  
  sub doSomeOpearation {
      my ($n, $c) = @_;
      #...
      return;
  }
  
  HelpMessage(1) unless ($node &amp;&amp; $command);
  
  =head1 NAME
  
  run_command - Run Commands on SVC Server
  
  =head1 SYNOPSIS
  
    --node,-n       Node name (required)
    --command,-c    Command (required)
    --help,-h       Print this help
  
  =head1 VERSION
  
  1.00
  
  =cut
  </code></pre>
  <p>The script works fine in positive scenario, i.e., if I pass 2 arguments to the script its printing those arguments in the screen.</p>
  <p>But, if I pass only one argument the script, it should go to <code>HelpMessage</code> function. Instead of that here script gives me <code>Use of uninitialized value $command in concatenation (.) or string at script2.pl line 14.</code> warning and prints <code>END</code> message too.</p>
  <p>How can I print <code>HelpMessage</code> and exit from the script unless there are 2 arguments?</p>