#!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 $_} } }