in reply to Re^2: How to read a file containing filenames and pass as input to perl script?
in thread How to read a file containing filenames and pass as input to perl script?
my @values = map { my $ch = $thingy->first_child( $_ ); $ch ? $ch->text : "" } qw( DOCNUM MESTYP SNDPRN RCVPOR RCVPRN );
Also, as I mentioned, you probably don't need to create a new Twig and CSV objects for each file. Declaring the sub inside the loop makes no sense, either.
#!/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 ); $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, }, ); while (my $xmlfile = <$list>) { chomp $xmlfile; $twig->parsefile($xmlfile); }
($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^4: How to read a file containing filenames and pass as input to perl script?
by Kal87 (Novice) on Apr 23, 2018 at 14:20 UTC | |
by hippo (Archbishop) on Apr 23, 2018 at 14:47 UTC | |
by poj (Abbot) on Apr 23, 2018 at 15:20 UTC | |
by Kal87 (Novice) on Apr 23, 2018 at 15:53 UTC |