in reply to Creating a xml file in chunks

XML::LibXML is great for handling existing XML documents, its XML::LibXML::Reader can even process large files that don't fit into memory. The distribution has no tool to produce such large files, though. I'd probably use XML::Writer or fill the data into a template. You can use XML::LibXML to create the template for you (but you'd still need to output the opening and closing root tags):
#!/usr/bin/perl use warnings; use strict; use Text::CSV_XS; use XML::LibXML; use Template; print "<ROOT>\n"; my $doc = 'XML::LibXML::Document'->new('1.0', 'utf-8'); my $line_tag = $doc->createElement('alpha'); $line_tag->setAttribute(name => '[% alpha %]'); for my $other (qw( beta gamma )) { my $other_tag = $doc->createElement($other); $other_tag->setAttribute(name => "[% $other %]"); $line_tag->appendChild($other_tag); } my $template = $line_tag->toString(1) . "\n"; my $csv_init = { binary => 1, auto_diag => 1, allow_whitespace => 1, sep_char => ';', eol => $/, quote_char => undef, }; my $csv = 'Text::CSV_XS'->new($csv_init); my @header = @{ $csv->getline(*DATA) }; my %rec; $csv->bind_columns(\@rec{@header}); my $tt = 'Template'->new; my $compiled_template = $tt->template(\$template); while ($csv->getline(*DATA)) { $tt->process($compiled_template, \%rec); } print "</ROOT>\n";

Update: Code modified to compile the template just once.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Creating a xml file in chunks
by vagabonding electron (Curate) on Jul 13, 2016 at 17:06 UTC

    Thank you very much choroba! I never used Template before, but it looks very interesting and I will try it now. In the meantime I have run XML::Writer with the real data, as you and haukex proposed - it does write the output file continuously and saves up the memory. Now I have two good options. Thanks again!