[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: perl file i/o
On Sat, 6 Dec 1997, shahar shocron wrote:
> open(FILE, "+<$file");
> while(<FILE>);
> {
> &change_record;
> print FILE $new_record;
> }
> close(FILE);
1. is the record you're writing of the exact same size as the record
you're reading? if not, this method cannot work.
2. if the answer to '1' is 'yes', then after each read, you need to seek
backwards in the file (using the perl 'seek' function) the ammount of
characters you've read, and then you may write on top of that record.
3. if the answer to '1' is 'no', then you cannot write to the same file -
create a temporary file, write everything to it, and after you've done
and closed both files, rename the new file to the old file's name (this
will also remove the old file from the system).
4. check the return value of any function call you make (open, close,
print) to look for errors - if youll assume they always work, you'll
get very buggy programms...
this has nothing to do with perl - it has to do with any programming
language.
guy