Random File Access

If you're adventurous, you can do random reads and writes within a file, as previously mentioned. The following sections briefly cover some tools you'll need to do random reads and writes; they are not covered more extensively because you shouldn't need them often.

Opening Files for Read and Write

Until now, you've looked at three methods for opening files. Files could be opened for reading, they could be opened for writing, or they could be opened for appending. Files can also be opened for both reading and writing at the same time. Table 15.1 lists the various modes available for opening files.

Table 15.1. Summary of Open Modes
open CommandReading?Writing?Append?Creates If Does Not Exist?Truncates Any Existing Data?
open(F, ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.