Generating random XML documents I'm trying to generate a fresh XML file using Perl XML::Mini::Document. It's working fine, but I don't know whether it's the right way to do it.  Performance is the problem for me; it takes more time when the when record count increases.

Is there any other module better doing than this one in performance and easier way?

#!/usr/bin/perl -w

use warnings;
use XML::Mini::Document;

my $outfile = "D:/Test.xml";

my $nSequence = 1000;
my $sRandom_Name = "";
my $sRandom_Desc = "";
my $newDoc = XML::Mini::Document-&gt;new();
my $newDocRoot = $newDoc-&gt;getRoot();
my $xmlHeader = $newDocRoot-&gt;header('xml');
$xmlHeader-&gt;attribute('version', '1.0');
$xmlHeader-&gt;attribute('encoding', 'UTF-8');

my $records= $newDocRoot-&gt;createChild('records');

for(0..9) {

   for(1..6) { 
      $sRandom_Name = $sRandom_Name.(chr(int(rand(25) + 65)));
   }
   for(1..15) { 
      $sRandom_Desc = $sRandom_Desc.(chr(int(rand(25) + 97)));
   }

   my $record = $records-&gt;createChild('record');

   $record-&gt;createChild('ID')-&gt;text($nSequence=$nSequence+1);
   $record-&gt;createChild('Name')-&gt;text($sRandom_Name);
   $record-&gt;createChild('Desc')-&gt;text($sRandom_Desc);

   print $newDoc-&gt;toFile($outfile);
}


My output should look like this one:




&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
   &lt;records&gt;
    &lt;record&gt;
         &lt;ID&gt;1001&lt;/ID&gt;
         &lt;Name&gt;ASDSDF&lt;/Name&gt;
         &lt;Desc&gt;ASDFsdsdfcwefSC&lt;/Desc&gt;
      &lt;/record&gt;
      &lt;record&gt;
         &lt;ID&gt;1002&lt;/ID&gt;
         &lt;Name&gt;KDFNND&lt;/Name&gt;
         &lt;Desc&gt;WEFsdssccwefSC&lt;/Desc&gt;
      &lt;/record&gt;
      &lt;record&gt;
         &lt;ID&gt;1003&lt;/ID&gt;
         &lt;Name&gt;PORJDX&lt;/Name&gt;
         &lt;Desc&gt;XceFsdsdfcASmsd&lt;/Desc&gt;
      &lt;/record&gt;
      .
      .
      .
   &lt;/records&gt;
Yes, that's pretty good. It's essential to include use strict at the top of every Perl program you write, and use warnings is preferable to -w on the command line. You should also avoid capital letters in identifiers for lexical variables, as they are reserved for use in global identifiers such as package names

I would write something more Perlish like this

#!/usr/bin/perl

use strict;
use warnings;

use XML::Mini::Document;

use constant OUTFILE =&gt; 'D:/Test.xml';

sub rand_letter { chr(ord('A') + rand(26)) }

my $new_doc = XML::Mini::Document-&gt;new;
my $root    = $new_doc-&gt;getRoot;
my $header  = $root-&gt;header('xml');
$header-&gt;attribute(version  =&gt; '1.0');
$header-&gt;attribute(encoding =&gt; 'UTF-8');

my $records= $root-&gt;createChild('records');

my $sequence = 1000;

for ( 0..9 ) {

    my $record = $records-&gt;createChild('record');

    my ($random_name, $random_desc);
    $random_name .= rand_letter for 1 .. 6;
    $random_desc .= rand_letter for 1 .. 15;

    $record-&gt;createChild(ID   =&gt; ++$sequence);
    $record-&gt;createChild(Name =&gt; $random_name);
    $record-&gt;createChild(Desc =&gt; $random_desc);
}

open my $fh, '&gt;', OUTFILE or die $!;
select $fh;
print $new_doc-&gt;toString;