Files are like statement labels designated by a string without a special initial character. It is recommended that you use all capitals in such labels
|
STDIN STDOUT STDERR (and diamond <> null name) have been introduced and correspond to UNIX stdin, stdout and stderr (and concatenation of argument files if <> operator)
|
Filehandles allow you to address general files and the syntax is similar to UNIX standard I/O (stdio.h) support
-
open(FILEHANDLE, "unixname"); # opens file unixname for reading -- can use <
-
open(FILEHANDLE, ">unixname"); # opens file unixname for writing
-
open(FILEHANDLE, ">>unixname"); # opens file unixname in append mode
|
close(FILEHANDLE); # closes file
|
Errors are handled with die construct:
|
open(FH, '>' . $criticalfile) || die("Print an error message if file can't be opened\n"); # Note how we add '>' (or '>>') to file name stored in Perl variable
|