Hi there,
I'm using the below perl script to process an XML file where the filename is passed as an argument during runtime (Argv[0]) to the script.
This works well, however, I would like to take this up a notch. I have another file (let's call it filename_list.txt) that contains a list of filenames (with absolute paths). Say the first two lines in that file read like this:
/home/kal/assemble.xml
/home/tom/Venice.xml
I expect thousands of lines in filename_list.txt
I'm looking to update the script so that it reads each line of filename_list.txt, and executes the twig and CSV bit for each file. Not sure how to get this going, could someone please help? I've attempted to use another bash script with a while, but it would be great if someone could suggest a faster method that involves just this perl script.
use Text::CSV_XS;
use XML::Twig;
my $csv = Text::CSV_XS->new({'sep_char' => "|",}, );
my $twig = XML::Twig->new( );
twig_handlers => {'EDI_DC40' => \&process_EDI_DC40,}, );
$twig->parsefile( $ARGV[0] );
sub process_EDI_DC40 {
my( $twig, $thingy ) = @_;
my @values = map { $thingy->first_child( $_ )->text }
qw(DOCNUM MESTYP SNDPRN RCVPOR RCVPRN);
$csv->say( *STDOUT, \@values );
+ }