title: Writing a macro in Perl
body: <pre><code>open $FP, '&gt;', $outfile or die $outfile." Cannot open file for writing\n";
  </code></pre>
  
  <ul>
  <li><p>I have this statement a lot of times in my code.</p></li>
  <li><p>I want to keep the format same for all of those statements, so that when something is changed, it is only changed at one place.</p></li>
  <li><p>In Perl, how should I go about resolving this situation?</p></li>
  <li><p>Should I use macros or functions?</p></li>
  </ul>
  
  <p>I have seen this SO thread <a href="https://stackoverflow.com/questions/2521188/how-can-i-use-the-macros-in-perl">How can I use macros in Perl?</a>, but it doesn't say much about how to write a general macro like</p>
  
  <pre><code>#define fw(FP, outfile) open $FP, '&gt;', \
          $outfile or die $outfile." Cannot open file for writing\n";
  </code></pre>