Introduction to Pipes and Streams using Perl

This module discusses reading and writing to files and communicating with other programs using Perl Pipes.
Some of the subjects you will learn about in this module include:

How streams work

Using file streams

Using pipes to communicate with other programs

Sending email from Perl

In the process, you will build and experiment with the second part of our class project, the email program.
When you are finished with this module you will understand how to use streams and pipes well enough to write your own programs using these techniques.

Simple recipes for opening files and pipes in Perl

Whenever you execute I/O on a file in Perl, you do so through what in Perl is called a filehandle.
A filehandle is an internal name for an external file. It is the job of the open function to make the association between the internal name and the external name, and it is the job of the close function to break that association.
For your convenience, Perl sets up a few special filehandles that are already open when you run. These include STDIN , STDOUT , STDERR , and ARGV .
Since those are pre-opened, you can use them right away without having to go to the trouble of opening them yourself:

Output Handles

STDOUT and STDERR are output handles, and STDIN and ARGV are input handles.
They are in all capital letters because they are reserved words in Perl, much like the

@ARGV array and

%ENV hash

are.
Their external associations were set up by your shell.
You will need to open every other filehandle on your own.
Although there are many variants, the most common way to call Perl's open() function is with three arguments and one return value:

OK = open(HANDLE, MODE, PATHNAME)

The following definitions hold:

OK : will be some defined value if the open succeeds, but undef if it fails;

HANDLE: should be an undefined scalar variable to be filled in by the open function if it succeeds;

MODE : is the access mode and the encoding format to open the file with;