Chapter 1Reading from Files
Our first concern when processing text is to get the text into our program, and perhaps the most common place to source text is from the humble file. Whether it’s log files from a server, exports from database, or text you’ve written yourself, there’s lots of information that lives on the filesystem. Learning to read from files effectively opens up a world of text to process.
Throughout the course of this chapter, we’ll look at how we can use Ruby to reach text that resides in files. We’ll look at the basics you might expect, with some methods to straightforwardly read files in one go. We’ll then look at a technique that will allow us to read even the biggest files in a memory-efficient way, by treating files as ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access