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 I am doing that reads the entire file and re-writes the entire file:


$var1 = '106253498';
open(FILE, "my.file");
@file = <FILE>;
close(FILE);
open(FILE, "my.file");
chomp @file;
foreach my $line (@file){
        if ($line =~ /^$var1\|/){
                #do my data changes
                $line = "asdf1234";#where asdf1234 is my changes
        }
        print FILE $line . "\n";
}
close(FILE);


Can anyone offer a suggestion? My issue is that the data that is coming in is x length (where x is a dynamic space) and the value I am writing back to the line can be a max of x+10 and a min of x-10..

Reply via email to