in reply to Creating a xml file in chunks
#!/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 |