title: Perl script to populate an XML file
body: <p>I am working on a Perl script which needs to populate an XML file based on user input. The user would provide a country name and a city name. If he/she provides: japan and e, I need to populate that in the japan tag - but as the last entry. How best can I achieve this? The cities in country tag can be many. How can I add a city as a last tag inside corresponding country tag?</p>
  
  <p>How can I reach at the end of relevant country tag each time I need to add a city?</p>
  
  <p>PS: I am not using any in-built data structures to store data. I am just adding dumb lines in the file.</p>
  
  <p>Samlple output XML file:</p>
  
  <pre><code>&lt;country name="japan-"&gt;
    &lt;city&gt;a&lt;/city&gt;
    &lt;city&gt;b&lt;/city&gt;
    &lt;city&gt;c&lt;/city&gt;
    &lt;city&gt;d&lt;/city&gt;
  &lt;/country&gt;
  &lt;country name="china-"&gt;
    &lt;city&gt;aa&lt;/city&gt;
    &lt;city&gt;bb&lt;/city&gt;
    &lt;city&gt;cc&lt;/city&gt;
    &lt;city&gt;dd&lt;/city&gt;
  &lt;/country&gt;
  </code></pre>
  
  <p>I've a more concrete question, <em><a href="https://stackoverflow.com/questions/4301435/change-an-xml-file-content-via-perl-script">Change an XML file content via Perl script</a></em>.</p>