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 );
+ }
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.