Thanks Ken. I can see some resutls now however the following issues exists:

(1)errors:
readline<> on unopened filehandle at line33
which is : while (<$in_fh>)

(2)my FILE0 is being skipped and only FILE1 and FILE2 are being processed

(3)Could you please give me quick explanation of whats going on within the subroutine write_xml_contents so that I can tweak my output as I desire.
here is my code:

#!/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', Fil +e2 => 'FILE2.xml'); #my $out_fh = \*STDOUT; my $key_file = 'File0'; my @feature_files = qw{File1 File2}; print $out_fh '<Key="1234">'; write_xml_content($key_file, $source_file_for{$key_file}, $out_fh, ' ' + x 4); print $out_fh "\n".' <Status="in use"/> <Features>'; 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".' </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, $_; } }


In reply to Re^4: copy XML elements from one file to another by Anonymous Monk
in thread copy XML elements from one file to another by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.