title: How can I use "here-doc" to print lines to a file?
body: <p>Basically, this is the result of my programming and using Google for the last half an hour trying to achieve a simple thing: pick up user inputs from <code>STDIN</code> and write them into a structured XML file as the output. Below is my ugly code:</p>
  <pre><code>#!/bin/perl
  print &quot;img URL = ?    &quot;;
  $img = &lt;&gt;;
  chomp($img);
  print &quot;filename = ?    &quot;;
  $filename = &lt;&gt;;
  chomp($filename);
  
  # now write xml with inserted contents to a file:
  open (CARDFILE, &quot;&gt;&gt;$filename&quot;);
  print CARDFILE &quot;&lt;card&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;img&gt;$img&lt;/img&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;type&gt;$type&lt;/type&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;expansion&gt;$expansion&lt;/expansion&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;keyword&gt;$keyword&lt;/keyword&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;color&gt;$color&lt;/color&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;linkcolor&gt;$linkcolor&lt;/linkcolor&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;kickercolor&gt;$kickercolor&lt;/kickercolor&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;cost&gt;$cost&lt;/cost&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;strength&gt;$strength&lt;/strength&gt;\r\n&quot;;
  print CARDFILE &quot;    &lt;health&gt;$health&lt;/health&gt;\r\n&quot;;
  print CARDFILE &quot;&lt;/card&gt;&quot;;
  close (CARDFILE);  
  </code></pre>
  <p>I am new to Perl, but I could tell some of the significant problems in my code:</p>
  <ol>
  <li><p>Use two lines to first receive <code>STDIN</code> then <code>chomp()</code> it to get rid of the trailing carriage return. Should there be a one-liner?</p>
  </li>
  <li><p>I cannot work out how to use the &quot;here-doc&quot; thing to print multiple-lines to file in one go. Without the <code>CARDFILE</code> file handle, I can use here-doc syntax to print all strings to <code>STDOUT</code> in a single print statement. Now I have to call the print function multiple times.</p>
  </li>
  <li><p>For these <code>&quot;\r\n&quot;</code>s, is there a way to use a different function so I don't have to remember to manually insert them after each line?</p>
  </li>
  </ol>