Hi Monks,

I would like to know the best way to append a file (huge,in Terra bytes) to another file.

Both source and destination could be of Terrabytes in Size.

As of now, am using
use File::Copy; open ( my $s, "<", "source" ) or die "Could not open source file: $!\n +"; open ( my $d , ">>", "dest" ) or die "Could not open destination file +: $!\n"; copy($s, $d) or die "Could not copy source to dest : $!\n"; (close $s && close $d ) or die "Could not close file handles : $!\n";

But some time, the above code says "Could not close file Input/Output error", and destination file is corrupted. I've noticed the line Note that passing in files as handles instead of names may lead to loss of information on some operating systems; it is recommended that you use file names whenever possible. from http://search.cpan.org/~rjbs/perl-5.16.0/lib/File/Copy.pm

Am not sure, whether passing file handle to copy is causing this issue.

Finally, I would want to know the right and best way to append a to another file with out consuming memory.

Thanks in Advance.

In reply to Best way to append bigger files 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.