title: Create a directory in Perl for a logfile if it does not exist
body: <p>I have a Perl script which takes a few arguments. It is executed like this:</p>
  
  <pre><code>exec myscript.pl --file=/path/to/input/file --logfile=/path/to/logfile/logfile.log
  </code></pre>
  
  <p>I have the following line in the script:</p>
  
  <pre><code>open LOGFILE, "&gt;&gt;$logFilePath" or die "Can't open '$logFilePath': $!\n";
  </code></pre>
  
  <p>Where <code>$logfilePath</code> is taken from the command line.
  If there is a path, /path/to/logfile/, but no logfile.log, it just creates it (which is the desired action). However, it fails to start if there is no such path. How can I make the script create the path for the logfile, if it does not exist prior to running the script?</p>