in reply to Re: Re: Opening a file for reading or writing (was: Newbie)
in thread Opening a file for reading or writing (was: Newbie)
Inplace modification of text files is considered harmful. I suggest that you write your output first to a second file and then rename the first file to a backup filename and the second file then to the original filename.
If you are bent on modifying a file in place (which is a bad idea while developing a program), just take a look at the documentation for the open() call :
open(DBASE, '+<$file') # open for update or die "Can't open '$file' for update: $!";
But I really really really have to recommend that you let your script output the stuff to the console first, and then simply redirect the console output into a new file. This is much much safer, and Perl has the -i command line switch which lets you switch on the in place modification easily.
|
|---|