Hi Ken,
I encountered exactly the same problem today: How to read a file
AND change something in it? I was not able to do both of them at
the same time.
I am sure there is a more correct way to do it, but my solution (in
the spirit of TIMTOWTDI) was to write to a temporary file and then
rename the temporary file to the name of the original file, like:
open FILE, "original.txt" or die "Cannot open file original.txt ($!)\n";
open TEMP, ">temp.txt" or die "Cannot open file temp.txt ($!)\n";
foreach my $line (<FILE>){
$line =~ s/find/replace/gi ;
print TEMP "$line\n";
}
close FILE;
close TEMP;
rename "temp.txt", "original.txt;
It works, but as I say, I am sure, this is not the best way to do it.
Therefore, I am just as curious as you, what the experts will tell us.
By the way, dear experts, I am really grateful for the time and effort
you spend helping us newbies. I learned a lot since I subscribed to
the list. Thank you!
Greetings from a sunny Cologne, Germany
Anette
> Hi,
>
> I have a file with say the value "02" in it.
>
> I can open the file, lock the file, read the value, increment the
> value and do a write but the write always appends and never
> over-writes the exisitng value. I of course then unlock and close.
>
> I do a seek before the write to the beginning of the file, even
> checked with "tell" and it returns "0",but the following print or
> syswrite always appends.
>
> Why? How do I over-write?
>
> Thanks
>
> Ken
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]