title: Use of uninitialized value $domain in concatenation (.) or string
body: <p>I wrote a script today. The purpose of this is to automatically add new virtual host to Apache. The script should be executed using this command: </p>
  
  <pre><code>./new_vhost.pl --add --domain google.com --client google. 
  </code></pre>
  
  <p>However, it doesn't work well instead it throws me errors</p>
  
  <blockquote>
    <p>Use of uninitialized value $domain in concatenation (.) or string</p>
  </blockquote>
  
  <p>Have you guys experienced this before? I was thinking the cause was the '.' in google.com though I am not really sure about it. I'm still searching for answers on Google but unfortunately nothing could help me fix this.</p>
  
  <p>Code:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use Getopt::Long;
  use Cwd;
  use POSIX "strftime";
  
  my $dir = getcwd;
  my $conf = 'test.conf';
  
  my $domain = undef;
  my $client = undef;
  my $help = undef;
  my $ltime = undef;
  
  if (-e $conf) {
          sub usage {
                  die "Usage: $0 [--add | --remove] [--domain google.com] [--client google].\n";
          }
  
          usage unless @ARGV &gt; 3;
          GetOptions (
                  'add' =&gt; \&amp;add_vhost,
  #               'remove' =&gt; \&amp;rem_vhost,
                  'domain=s' =&gt; \$domain,
                  'client=s' =&gt; \$client,
                  'help' =&gt; \&amp;usage
          ) || usage;
  
          $domain = lc($domain);
          $client = uc($client);
          $ltime = localtime;
  
          sub add_vhost {
                  open (CONF, "&gt;&gt;$conf") || die "ERROR: unable to open $conf.\n";
                  print CONF "#***** Start of configuration for $domain. *****#";
                  print CONF "\n# Domain: $domain\n";
                  print CONF "# Client: $client\n";
                  print CONF "# Date: $ltime\n";
                  print CONF "&lt;VirtualHost *:1111&gt;\n";
                  print CONF "    ServerAdmin admin\@$domain\n";
                  print CONF "    DocumentRoot /var/www/html/$domain\n";
                  print CONF "    ServerName $domain\n";
                  print CONF "    ServerAlias www.$domain\n";
                  print CONF "    ErrorLog /var/log/httpd/$domain/$domain-error_log\n";
                  print CONF "    CustomLog /var/log/httpd/$domain/$domain-access_log common\n";
                  print CONF "&lt;/VirtualHost&gt;\n";
                  print CONF "#***** End of configuration for $domain. *****#\n";
                  close CONF;
                  if ($? != 0) {
                          die "Error: unable to create a new configuration.\n";
                  } else {
                          print "OK: new configuration for $domain has been added.\n";
                  }
          }
  } else {
          die "ERROR: $conf not found.\n";
  
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 37.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 38.
  Use of uninitialized value $client in concatenation (.) or string at ./new_vhost.pl line 39.
  Use of uninitialized value $ltime in concatenation (.) or string at ./new_vhost.pl line 40.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 42.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 43.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 44.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 45.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 46.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 46.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 47.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 47.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 49.
  Use of uninitialized value $domain in concatenation (.) or string at ./new_vhost.pl line 54.
  OK: new configuration for  has been added.
  </code></pre>
  
  <p>The test.conf after running the script.</p>
  
  <pre><code>#***** Start of configuration for . *****#
  # Domain:
  # Client:
  # Date:
  &lt;VirtualHost *:1111&gt;
      ServerAdmin admin@
      DocumentRoot /var/www/html/
      ServerName
      ServerAlias www.
      ErrorLog /var/log/httpd//-error_log
      CustomLog /var/log/httpd//-access_log common
  &lt;/VirtualHost&gt;
  #***** End of configuration for . *****#
  </code></pre>
  
  <p>But I was expecting something like this...</p>
  
  <pre><code>#***** Start of configuration for google.com. *****#
  # Domain: google.com
  # Client: GOOGLE
  # Date: Tue Apr  8 17:27:39 2014
  &lt;VirtualHost *:1111&gt;
      ServerAdmin admin@google.com
      DocumentRoot /var/www/html/google.com
      ServerName google.com
      ServerAlias www.google.com
      ErrorLog /var/log/httpd/google.com/google.com-error_log
      CustomLog /var/log/httpd/google.com/google.com-access_log common
  &lt;/VirtualHost&gt;
  #***** End of configuration for google.com. *****#
  </code></pre>