Chapter 2
Processing Standard Input

We’ve looked at how we can use Ruby to read data that exists on the filesystem. Another common source of information, though, is direct input to a script. This might be text that users input using their keyboard, or it might be text that’s redirected to your script from another process. From the perspective of Ruby, these two different types of input are actually the same thing, processed in the same way.

This source of input is called standard input, and it’s one of the foundations of text processing. Along with its output equivalents standard output and standard error, it enables different programs to communicate with one another in a way that doesn’t rely on complex protocols or unintelligible binary data, but instead on straightforward, human-readable text.

Learning how to process standard input will allow you to write flexible and powerful utilities for processing text, primarily by enabling you to write programs that form part of text processing pipelines. These chains of programs, linked together so that each one’s output flows into the input of the next, are incredibly powerful. Mastering them will allow you to make the most both of your own utilities and of those that already exist, giving you the most text processing ability for the least amount of typing possible.

Let’s take a look at how we can write scripts that process text from standard input, slotting into pipeline chains and giving us flexibility, reusability, and power.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.99.120