in reply to File I/O

This is straight out of the Perl Cookbook:

"Problem: You want to read in an old record from a binary file, change its values, and write back the record.
Solution: After reading the old record, pack up the updated values, seek to the previous address, and write it back.
"

And here is the accompanying style-challenged snippet, also directly from the Perl Cookbook:

use Fcntl; # for SEEK_SET and SEEK_CUR $ADDRESS = $RECSIZE * $RECNO; seek(FH, $ADDRESS, SEEK_SET) or die "Seeking: $!"; read(FH, $BUFFER, $RECSIZE) == $RECSIZE or die "Reading: $!"; @FIELDS = unpack ($FORMAT, $BUFFER); #update fields, then $BUFFER = pack($FORMAT, @FIELDS); seek(FH, -$RECSIZE, SEEK_CUR) or die "Seeking: $!"; print FH $BUFFER; close FH or die "Closing: $!";

Even better answers can be found in the perldocs, perlfaq5 under the topics "How can I manipulate fixed-record-length files?" and "How do I randomly update a binary file?"

Check into those online resources first (rather than just grabbing the Perl Cookbook's snippet); they will give you the best description, and a good understanding of the topic.

Hope this helps...

Dave

"If I had my life to do over again, I'd be a plumber." -- Albert Einstein