Previous Page Next Page

Chapter 4. Getting a Handle on Printing

4.1. The Filehandle

By convention, whenever your program starts execution, the parent process (normally a shell program) opens three predefined streams called stdin, stdout, and stderr. All three of these streams are connected to your terminal by default.

stdin is the place where input comes from, the terminal keyboard; stdout is where output normally goes, the screen; and stderr is where errors from your program are printed, also the screen.

Perl inherits stdin, stdout, and stderr from the shell. Perl does not access these streams directly but gives them names called filehandles. Perl accesses the streams via the filehandle. The filehandle for stdin is called STDIN; the filehandle for stdout is called STDOUT; and the filehandle for stderr is called STDERR. Later, we'll see how you can create your own filehandles, but for now we'll stick with the predefined ones.

The print and printf functions by default send their output to the STDOUT filehandle, your screen.

Previous Page Next Page