Basic HTML version of Foils prepared Sept 20 97

Foil 63 FileHandles

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


1 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
2 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)
3 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
4 close(FILEHANDLE); # closes file
5 Errors are handled with die construct:
6 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

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Sep 21 1997