Perl Tutorial 3, IO
- Command Line, Standard Input and Standard Output
Perl can accept command line input three ways. Two of these work together with
the command line that was used to start a program. The third can accept
input into a running program. If additional arguements are included on
the line that starts a Perl program, they are split on whitespace and
put into the array @ARGV. They can be accessed just like normal array
values. If the arguments are files that can be read py the program they
will be opened on the default filehandle <>. A running program can
accept input via the standard input filehandle or . Output using
the print statement defaults to STDOUT, but it can be routed to any
filehandle.
- Files and Filehandles
A filehandle is just an easy way to designate a IO object. The open
statement is used to make that happen. The syntax is easy, just two
arguments. The filehandle is first. It is as arbitrary string that will
be used to acces the object. Next is a string with instructions. The
instructions can take 3 basic forms. If the string contains just a
filename or a filname preceded by a <
it will be opened for input. If it is a filename preced by a > it will
be opened for as a new file for output. If it is a filename preced by a
>> it will be opend as a file for output and writing will begin at the
end of the current file.
- Pipes
A filehandle can be opened on another process by using the 'pipe'
symbol |.