Hello Tom! Hello All! You helped a lot Tom. Still... I have some trouble.
For sure $^I is easier to use. Although in my case i would need to rewrite a lot of code. I will do it, but it will take a while to test it. I found good information on $^I at http://perldoc.perl.org/perlfaq5.html#How-can-I-use-Perl%27s-%27-i%27-option-from-within-a-program%3F I found some information for seek() at http://perldoc.perl.org/functions/seek.html I tryed to use seek but it did not work. Can you help me on that, please? I am using Windows XP. The following example writes at the end of the file. use strict; my $file = "teste_rw.txt"; open (FILE, "+<", $file) or die "Can not open $file: $!."; for my $line (<FILE>) { print $line; seek(FILE, 0, 1); print FILE "b\n"; seek(FILE, 0, 1); } my $a_while = 2; sleep($a_while); seek(FILE, tell(FILE), 0); close FILE; Thank you. Bruno ""Tom Phoenix"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On 5/14/07, Bruno Schroeder <[EMAIL PROTECTED]> wrote: > >> I am trying to read and write in a file, I am using something like: >> >> open (FILE, "+<teste_rw.txt") or die "I couldn't open the file."; > > A little better is to include $! in the message, maybe like this: > > open FILE, "+<teste_rw.txt" > or die "Can't open r/w 'teste_rw.txt': $!"; > >> for my $line (<FILE>) { >> print $line; >> if($line eq "X\n") >> { >> print FILE "b\n" > > Depending upon your I/O system, you may need to use seek() whenever > you switch from reading to writing, or from writing to reading. > > It looks as if you're trying to edit a text file "in place". Although > that's possible for some simple cases, it's generally easier to use > Perl's $^I functionality. > > Hope this helps! > > --Tom Phoenix > Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/