reading/writing to a ascii file

2003-10-28 Thread Farrington, Ryan
Title: reading/writing to a ascii file Ok guys here is the pickle I'm in now =-) I need to read from a ASCII file and only modify the lines that match a variable. I do not want to read the entire file into memory and write the entire file out each time I need to make a change. Here is what

RE: reading/writing to a ascii file

2003-10-28 Thread Erich C. Beyrent
ok let's say I have a 500,000 line file... What I want is for the script to read the file in line by line and only change the 1 line I am looking for. ex: line 550 contains the line I am looking for I want to change that line and not have to re-create the file. You could do this: perl -i -p

RE: reading/writing to a ascii file

2003-10-28 Thread Thomas, Mark - BLS CTR
Ryan, it's easier than you think: open(IN, $inputfile) or die can't open $inputfile: $!; open(OUT,$outputfile) or die can't open $outputfile: $!; while (IN){ s/$string/$replacement/g; print OUT $_; } close IN; close OUT; rename($outputfile, $inputfile) or die can't rename... $!;

RE: reading/writing to a ascii file

2003-10-28 Thread Farrington, Ryan
Title: RE: reading/writing to a ascii file That is still opening and reading the entire file and then creating an entire new file... I may run into instances where the file will be opened and modified many times. -Original Message- From: Thomas, Mark - BLS CTR [mailto:[EMAIL

RE: reading/writing to a ascii file

2003-10-28 Thread Thomas, Mark - BLS CTR
That is still opening and reading the entire file and then creating an entire new file... No, it's not. It reads only one line at a time into memory. This is quite different from your version which read the entire file into memory. Are you looking to avoid *both* reading the file into memory

RE: reading/writing to a ascii file

2003-10-28 Thread Beckett Richard-qswi266
Ok guys here is the pickle I'm in now =-) I need to read from a ASCII file and only modify the lines that match a variable. I do not want to read the entire file into memory and write the entire file out each time I need to make a change. Here is what I am doing that reads the entire file