use warnings;
use strict;
use Text::CSV;
use XML::Twig;
my %data;
my $twig = XML::Twig->new(
twig_print_outside_roots => 1,
twig_roots => {
'HOST_NAME' => sub { $_[1]->set_text($data{host})->print },
'HOST_IP' => sub { $_[1]->set_text($data{ip} )->print },
'HOST_MAC' => sub { $_[1]->set_text($data{mac} )->print },
} );
my $XML = <<'END_XML'; # just for demo
END_XML
my $csv = Text::CSV->new({binary=>1,auto_diag=>2});
while ( my $row = $csv->getline(*DATA) ) {
@data{"host","ip","mac"} = @$row;
# here's where you'd need to match up XML file with data row
$twig->parse($XML);
}
$csv->eof or $csv->error_diag;
__DATA__
hosta,1.1.1.1,00000C123456,
hostb,2.2.2.2,00000C123457,
hostc,3.3.3.3,00000C123458,
####
hosta
1.1.1.1
00000C123456
hostb
2.2.2.2
00000C123457
hostc
3.3.3.3
00000C123458