1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use strict; use warnings; use XML::Twig; my $file1 = $ARGV[0] || die 'No file1'; my $FileResult = $ARGV[3] || 'result.txt'; open( my $FhResult, '>', $FileResult ) or die("Unable to open file $FileResult\n$!"); my $twig1= XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $attr_value = $_->{'att'}->{'value'} || 'fault'; print $FhResult $attr_name . ","; }, }, ); print $FhResult( (split('_', $file1,2))[0] . ',' ); $twig1->parsefile($file1);
my $file1 = argv[1], argv[2], argv[3]… die 'No file';
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use strict; use warnings; use XML::Twig; my @files = @ARGV or die 'No files'; my $FileResult = 'result.txt'; open( my $FhResult, '>', $FileResult ) or die "Unable to open file $FileResult\n$!"; for my $file (@files) { my $twig1 = XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $attr_value = $_->{'att'}->{'value'} || 'fault'; print $FhResult $attr_name . ","; }, }, ); print $FhResult ( split( '_', $file, 2 ) )[0] . ','; $twig1->parsefile($file); } close $FhResult;
$result = $expat->parse($arg);
my $attr_value = $_->{'att'}->{'value'} // 'fault';
my $attr_value = defined $_->{'att'}->{'value'} ? $_->{'att'}->{'value'} : 'fault';
1 2
my $attr_value = $_->{'att'}->{'value'}; $attr_value = 'fault' if not defined $attr_value;