Hi - > -----Original Message----- > From: Galbayar Dorjgotov [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, January 21, 2003 8:32 PM > To: [EMAIL PROTECTED] > Subject: Random Access File > > > > How to access and create RandomAccessFile > could u send me simple example? >
All (most - i.e. STDIN,etc. are non-seekable) files opened with 'open' have an internal 'position'; you can read and set this position with the 'tell' and 'seek' commands: my $pos = tell FILE; # gets current position seek FILE, $pos, 0; # sets position to $pos The last parameter in 'seek' is whence: 0 == relative to the beginning of the file, 1 == relative to current position, 2 == relative to the end of the file. Reading and writing start at the current position and resets the postion to the end of what they have read or written. The rest is up to you: developing some kind of indexing, etc. Warning: on some systems (Windows) you may have trouble with positioning in test mode files as the \n translation may replace 1 character with 2 characters; it is always safer to set files to binary mode: binmode FILE; before using seek and/or tell. Aloha => Beau. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]