in reply to File I/O
Depends upon your definition of a "record". If your file contains fixed length records then is is fairly trivial to use perlfunc:seek and perlfunc:tell to position the file pointer to a specific record and overwrite the data in-place.
However, as most PC based filesystems do not have fixed-length record filetypes built-in as many mainframes do, fixed length records are fairly few and far between in the PC world. Most files therefore variable length "records", which means that you have to scan the file sequentially and remember the start position and length of each record as you go. It also means that you have to re-write every subsequent record unless your update is exactly the same length as the preceeding one.
However, the saving grace is that this has been done before, and being perl, that code is available to you on CPAN. Take a look at Tie::File. If your using a reasonably modern version of perl, this probably came with your distribution. It allows you to treat a file of fixed or variable length records as an array and takes care of all the file pointer shuffling and throws in some intelligent buffering to boot.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: File I/O
by demerphq (Chancellor) on Sep 23, 2003 at 22:02 UTC | |
by BrowserUk (Patriarch) on Sep 23, 2003 at 22:43 UTC | |
by demerphq (Chancellor) on Sep 23, 2003 at 23:20 UTC | |
by BrowserUk (Patriarch) on Sep 23, 2003 at 23:35 UTC | |
by jonadab (Parson) on Sep 23, 2003 at 23:59 UTC | |
| |
by demerphq (Chancellor) on Sep 24, 2003 at 00:12 UTC | |
|