#!/strawberry/perl/bin/perl
#use strict;
use warnings;
use autodie;
open my $out_fh, '>', 'out_data.txt';
my %source_file_for = (File0 => 'FILE0.xml', File1 => 'FILE1.xml', File2 => 'FILE2.xml');
#my $out_fh = \*STDOUT;
my $key_file = 'File0';
my @feature_files = qw{File1 File2};
print $out_fh '';
write_xml_content($key_file, $source_file_for{$key_file}, $out_fh, ' ' x 4);
print $out_fh "\n".'
';
for (@feature_files) {
open my $in_fh, '<', $source_file_for{$_};
write_xml_content($_, $in_fh, $out_fh, ' ' x 8);
close $in_fh;
}
print $out_fh "\n".'
';
sub write_xml_content {
my ($file_id, $in_fh, $out_fh, $indent) = @_;
while (<$in_fh>) {
chomp;
if (/^<\/?doc>$/) {
s/doc/$file_id/;
}
else {
if (/^$/) {
my $id = $1;
s/$id/$file_id-$id/;
}
$_ = ' ' x 4 . $_;
}
print $out_fh $indent, $_;
}
}