#!/usr/bin/perl use warnings; use strict; use Text::CSV_XS; use XML::Twig; my $csv = 'Text::CSV_XS'->new({ sep_char => '|', }); sub process_EDI_DC40 { my ($twig, $thingy) = @_; my @values = map { my $ch = $thingy->first_child( $_ ); $ch ? $ch->text : "" } qw( DOCNUM MESTYP SNDPRN RCVPOR RCVPRN ); unshift @values,'XML'; $csv->say (*STDOUT, \@values); } my $listfile = shift; open my $list, '<', $listfile or die $!; my $twig = 'XML::Twig'->new( twig_handlers => { EDI_DC40 => \&process_EDI_DC40, }, ); my $fcount = 1; while (my $xmlfile = <$list>) { chomp $xmlfile; print STDERR "$0 : about to process file # $fcount = '$xmlfile'\n"; $twig->parsefile($xmlfile); print STDERR "$0 : file $xmlfile' processed OK.\n"; $fcount++; $twig->purge; }