Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing to file

Status
Not open for further replies.

EchoCola

Programmer
Apr 13, 2004
48
US
When this code executes, i end up with a text file that is about 500megs and keeps growing, mind you the only thing in the input file is a single sentence.

Any ideas?

Code:
open (INFILE, "<merge1.txt") ||
	die ("Cannot open the file 1\n");
	
open (OUTFILE, ">outfile.txt") ||
	die ("Cannot open the file 2\n");

$line1 = <INFILE>;
$line1 = ("\U$line1\E\n");

print $line1;
while($line1 ne ""){
	
	if ($line1 ne ""){		
		print OUTFILE ($line1);
	}
}
 
I found out the problem i was missing the line:
Code:
$line1 = <INFILE>;
 
This:
while($line1 ne ""){
says to loop for as long as $line1 has any content. In the body of the loop, $line1 is never set to "" so it will loop forever writing to the outfile.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top