Opening a File (Revisited)
As you already know, to open a file for reading, you use the following statement:
open FILE_VAR, "<file_in.txt";
And to open a file for writing, you use this statement:
open FILE_VAR, ">file_out.txt";
Perl uses the special character > to indicate that it should open a file for writing and < for a read indicator.
Other special characters are recognized as well. For example, if you want to append to a file, use the >> indicator:
open LOG_FILE, ">>command.log";
Opening a Pipe
Suppose that you are going to write a report to the screen. If you just write the report, the data scrolls off the top of the screen. So to be nice, you want to write out a page of data and wait for the user to press a key. Then you would write ...
Get Perl for C Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.