
David4
Deleted
Mar 16, 2000, 11:54 PM
Post #1 of 3
(1289 views)
|
output in separate files
|
Can't Post
|
|
Hi, How can I get three output files? outfile1.txt for the first time of the loop, outfile2.txt for the second time of the loop and outfile3.txt for the third time of the loop. Thank you!!! David Here's the program: $tall = 'fruitfile2.txt'; open(OUT, '>outfile.txt'); open(TREES, "<$tall") or die "Couldn't open the fruitfile2.txt file for writing. !\n"; while (<TREES> ) { push @fruits,$_; } close(TREES); $prefer = 'testfile.txt'; open(LEAF, "$prefer") or die "Couldn't open the ". "testfile.txt file for writing.\n"; @fileArr = <LEAF>; close LEAF; for ($i=0; $i<=2; $i++){ foreach (@fileArr){ chomp; ($tmpStr= $_)=~ s/fruits/@fruits[$i]/g; print OUT "$tmpStr\n"; } } fruitfile2.txt: big red apples large juicy oranges small firm peaches testfile.txt: I like to eat fruits. I think fruits are delicious. How many fruits do you want? I like this line to be printed too.
|