- Process multiple documents into a single file

This is an example of one of the things that Perl does best, text and file manipulation. I wrote this for a specific project that entailed taking multiple single-page text files that were actually parts of multi-page files. This script allowed me to process as many single files as I needed into a multi-page file. With slight modification, this script can also filter-out items that are not to be transfered to the final document.


print "\nThis script will append multiple documents to a single document.\n";

print "\n\nWhat is the file to be written to? ";

$write_file = < STDIN >;

print "\nThe outfile is $write_file";

print "\n\nWhat file is to be processed? ";

$file = < STDIN >;

while($file != "no"){

open(INFILE, $file);
open(OUTFILE, " > > $write_file");
print OUTFILE "\n";

while(< INFILE >){

$aline = $_;
($first, $rest)= split(' ', $aline);
if($first eq $kill_char){
chop ($first);
$aline = $rest;
print OUTFILE "\n$aline";
print "\n$aline";

print OUTFILE "\n";
print "\nIf you would like to add another file, type the file name at the prompt.\n";
print "\nOtherwise, type -no- to exit\n";
print "Add another file? ";
$file = < STDIN >;