I'm basically using Perl to "cat long_file_list > mergedFile". My program runs on Windows and I would use DOS>type for the job but my argument list is too long. So I've written a tiny Perl program for the process and it works nicely for small ASCII files but fails for large binary files. Somehow Perl adds extra characters to the merged binary file as verified by DOS>dir. I'm using ActiveState Perl v5.16.3 built for MSWin32-x64-multi-thread. Why does this program fail for large binary file inputs and is there a better way to do it? And here is the program:
#!perl -w #test Perl's I/O for merging binary files #global initializations use strict; #require variable declaration sub merge_pieces (\@$); #function prototype #try the function my @inList = qw < in1 in2 in3 >; merge_pieces @inList, "out"; #function: merge files to create 1 overall file #input 1: $pieceList, reference to a list of file pieces #input 2: $outName, name of the merged file sub merge_pieces (\@$) { #get function inputs my ($pieceList, $outName) = @_; #user message print "Reconstituting file $outName from \n"; #open output file open my $fOut, ">", $outName or die "Unable to open file $outName for writing: $! \n"; #loop for all input files foreach my $toRead (@$pieceList) { #open file open my $input, "<", $toRead or die "Unable to open file $toRead for reading: $! \n"; #user message print " $toRead \n"; #read and write entire file while (<$input>) { print $fOut $_} } }

In reply to Binary file I/O problem by DavidZ

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.