If you're mostly just copying the contents of several files, perhaps consider not using a module at all.
Something along the lines of this code (following some Notes) might do what you want.
Notes:
-
You didn't specify exactly which parts of the source files were to be copied.
I'll leave you to make changes depending on your requirements.
-
IDs should be unique. I've added code to do this. Again, modify how you want.
-
I've added consistent indentation. You may want something different: change to suit.
-
Assumed a typo: s{<doc/>}{</doc>}
-
I've used a cut-down version of your data for demo purposes.
-
I'll leave you to replace Inline::Files and \*STDOUT with more appropriate I/O.
#!/usr/bin/env perl -l
use strict;
use warnings;
use Inline::Files;
my %doc_fh_for = (File0 => \*FILE0, File1 => \*FILE1, File2 => \*FILE2
+);
my $out_fh = \*STDOUT;
my $key_file = 'File0';
my @feature_files = qw{File1 File2};
print $out_fh '<Key="1234">';
write_xml_content($key_file, $doc_fh_for{$key_file}, $out_fh, ' ' x 4)
+;
print $out_fh ' <Status="in use"/>
<Features>';
for (@feature_files) {
write_xml_content($_, $doc_fh_for{$_}, $out_fh, ' ' x 8);
}
print $out_fh ' </Features>
<Other_Status/>
</Key>';
sub write_xml_content {
my ($file_id, $in_fh, $out_fh, $indent) = @_;
while (<$in_fh>) {
chomp;
if (/^<\/?doc>$/) {
s/doc/$file_id/;
}
else {
if (/^<ABC id="(\d+)">$/) {
my $id = $1;
s/$id/$file_id-$id/;
}
$_ = ' ' x 4 . $_;
}
print $out_fh $indent, $_;
}
}
Inline::Files data:
Output:
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.