You can append the files into the merged document, just like you are appending to the log file:

use strict; use warnings; ## open the 'merge' for writing ## this way you will only wrote in the files from this merge ## and not keep anything that is already in there ## to keep any pre-existing content, leave as # open(my $merge_fh, '>>', $targetfile) || die "Failed to append to ta +rget: $!"; ## always check for success on open/close FH operations open(my $merge_fh, '>', $targetfile) || die "Failed open \'$targetfile\' for merging: $!"; my @rpts = glob('//testserver/dir/*'); foreach my $x (@rpts) { ## open each file to be merged in turn open (my $fh, '<', $x) || die "Failed open \'$x\' for reading : $! +"; ## read out each line, printing it into the target file while (<$fh>){ print $merge_fh $_;} ## close up close $fh || die "Failed to close \'$x\' : $!"; } ## now all the files have been copied into the target, you are free to + close it. close $merge_fh || die "Failed to close $targetfile after merge : $!";

Update: Improved code

Just a something something...

In reply to Re: Append Text Files by BioLion
in thread Append Text Files by drodinthe559

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.