in reply to Changing records in a text file

The old and boring way to do it would be to open the file in read/write mode, read the contents into an array, make the changes to the array, rewind the file pointer, truncate the file handle and then write out the array. Oh, and don't forget to flock the file handle to stop anyone else trying to access the file.

But these days, it's much easier to just use Tie::File.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Changing records in a text file
by Anonymous Monk on Nov 15, 2006 at 16:48 UTC
    Thanks, I did try to write them back but the file is too large and every so ofter is just deletes a large chunk of codes.
    open (DB, ">".$codes_db) || die ("Can't open $codes_db"); flock (DB, 2) || die ("Can't lock $codes_db"); foreach $line(@buffer){ print DB "$line\n"; } flock (DB, 8) || die ("Can't close $codes_db"); close (DB) || die ("Can't close $codes_db");
    Is there anything I can do while the file is open in the while loop?