REVISED: Sunday, March 3, 2013
You will learn the basic fundamentals of Perl filehandles.
I. PERL FILEHANDLE DEFINITION
All input and output with Perl files is achieved through filehandling.
In Perl, files are given a name, a handle, basically another way of saying alias. A filehandle is nothing more than a nickname for the files you intend to use in your Perl scripts and programs.
Like any Perl identifier you could use letters, digits, and underscores; however, you should only use all uppercase letters for your filehandle identifier and do not start the filehandle with a digit.
II. PERL RESERVED FILEHANDLE NAMES
The following six Perl filehandle names have special properties: STDIN, STDOUT, STDERR, DATA, ARGV, and ARGVOUT. Only use these six filehandle names when you want to use their special properties.
The STDIN, standard in, filehandle is normally connected to your keyboard.
The STDOUT, standard out, filehandle is normally connected to your computer monitor.
The STDERR, standard error, filehandle is also normally connected to your computer monitor.
III. PERL FILEHANDLE EXAMPLES
If we have a long file name such as helloworld.txt, that we do not want to type over and over in our program, we could use HELLO as the file nickname or filehandle and the following statement to open the file.
open HELLO, "helloworld.txt";
In the above statement HELLO is the name of our filehandle. The filehandle is followed by a comma. The comma is followed by the name of our file in double quotes. The Perl statement is ended with a semi-colon. Now you can read and write from HELLO.
When you are done you can use the following statement to close helloworld.txt
How to Link to My Home Page
It will appear on your website as:"Link to ELCRIC OTTO CIRCLE's Home Page"
No comments:
Post a Comment