1 |
dpavlin |
364 |
#!/usr/bin/perl -w |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
|
5 |
|
|
foreach my $file (@ARGV) { |
6 |
|
|
|
7 |
|
|
open(XML,$file) || die "can't open '$file': $!"; |
8 |
|
|
|
9 |
|
|
my $xml; |
10 |
|
|
while (<XML>) { |
11 |
|
|
$xml .= $_; |
12 |
|
|
} |
13 |
|
|
|
14 |
|
|
close(XML); |
15 |
|
|
|
16 |
|
|
my $new_xml; |
17 |
|
|
|
18 |
|
|
sub to_v { |
19 |
|
|
my ($f,$sf) = @_; |
20 |
|
|
my $out = "v".$f; |
21 |
|
|
$out .= "^".$sf if ($sf); |
22 |
|
|
return $out; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
while ($xml =~ s/(^.+?<isis[^>]*>)(.+?)(<\/isis>)//s) { |
26 |
|
|
my ($pre,$data,$post) = ($1,$2,$3); |
27 |
|
|
$data =~ s/(\d{3})([\w\d]?)/to_v($1,$2)/esg; |
28 |
|
|
$data =~ s/v(v\d{3}\^\w)/$1/gs; |
29 |
|
|
$new_xml .= $pre.$data.$post; |
30 |
|
|
} |
31 |
|
|
$new_xml .= $xml; |
32 |
|
|
|
33 |
|
|
open(XML,"> $file-new") || die "can't create '$file-new': $!"; |
34 |
|
|
print XML $new_xml; |
35 |
|
|
close(XML); |
36 |
|
|
|
37 |
|
|
rename "$file-new","$file" || die "can't update original file '$file' with '$file-new': $!"; |
38 |
|
|
|
39 |
|
|
print "$file converted\n"; |
40 |
|
|
} |
41 |
|
|
|