This section covers getting information into programs and receiving data back from them.
several convenient ways to get information into a program. In this
book, I've emphasized opening files and reading in the information contained in
them, because it is frequently used, and because it behaves very much the same
way on all different operating systems. You've observed the
close system calls and how
to associate a filehandle with a file when you open it, which then is used to read
in the data. As an example:
open(FILEHANDLE, "informationfile"); @data_from_informationfile = <FILEHANDLE>; close(FILEHANDLE);
This code opens the file informationfile
and associates the filehandle FILEHANDLE with it. The filehandle is then used
within angle brackets
< > to actually
read in the contents of the file and store the contents in the array
@data_from_informationfile. Finally, the file is
closed by referring once again to the opened filehandle.
Perl allows you to read in any input that is automatically sent to your program via standard input (STDIN). STDIN is a filehandle that by default is always open. Your program may be expecting some input that way. For instance, on a Mac, you can drag and drop a file icon onto the Perl applet for your program to make the file's contents appear in STDIN. On Unix systems, you can pipe the output of some other program into the STDIN of your program with shell commands such as:
someprog | my_perl_program ...