Title: Joining Text Files
Hello Charles,
 
look this:
 
@files = ("file1.txt","file2.txt"); # how many as needed;
 
$i = ($#files + 2); # if you need the file+1.txt
 
open (file_out, ">file$i.txt");
 
foreach $file (@files) {
 
print file_out "$file\n\r";
 
 open (file_in, "<$file") or die "Cannot open $file file!";
 print file_out <file_in>;
 
 close file_in;
 
}
close file_out;
 
 
 
regards,
fabricio.
 
-----Mensagem original-----
De: Charles, Chris [mailto:[EMAIL PROTECTED]
Enviada em: Friday, September 26, 2003 12:44 PM
Para: [EMAIL PROTECTED]
Assunto: Joining Text Files

Hello all,

This is a case of knowing sort of what to do but not knowing which direction to head off in. Basically, here's what I would like to ultimately do with Perl...

I have a series of text files with specific names and the files are full of numbers. So lets say I have:

Filename: FILE1.TXT
Filename: FILE2.TXT

FILE1.TXT contains:
123
456
789

FILE2.TXT contains:
234
567
890

What I ultimately want is:

Filename: FILE3.TXT

...which would contain the following:

FILE1.TXT <-adding the filename as a "header" to each section
123
456
789
FILE2.TXT <-adding the filename as a "header" to each section
234
567
890

I'm fairly new to Perl but I know that none of this is too hard. I'm just having difficulty seeing the forest for the trees on where to begin. Any help provided would be greatly appreciated!

Thanks,
Chris

Reply via email to