- 论坛徽章:
- 0
|
回复 6# iakuf
3Q...我是直接当成文本文件读取 然后查找特定的字符了
#!/usr/local/bin/perl -w
my $dirname = $ARGV[0];
print "Rid\tDF1\tDF2\n";
# Get all XML file from the specified folder
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
while (defined($file = readdir(DIR))) {
# do something with "$dirname/$file"
if($file =~ /xml$/){
#print $dirname.'\\'.$file, "\n";
readInfo($dirname.'\\'.$file);
}
}
closedir(DIR);
exit;
# Get content from the file
sub readInfo{
my $f = shift;
my $F;
open($F, $f) || die "open $f failed";
my $idx = 0;
while(<$F>){
chmod;
my $str = $_;
if($str =~ m/>(.*)<\/Rid/i){ # >1-25900-309</RId
print $1;
$idx++;
}elsif($str =~ m/>(.*)<\/DF1/i){ # >1-NC4TP6</DF1
print "\t",$1;
$idx++;
}elsif($str =~ m/>(.*)<\/DF2/i){ # >1-NC4TP6</DF1
print "\t",$1;
$idx++;
}
last if($idx == 3);
}
print "\n";
close($F);
} |
|