File I/O in Perl

Revision as of 10:23, 12 April 2008 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Use a filehandle to open a file in Perl. The filehandle identifier doesn't have a prefix like other Perl identifiers.

To open a file use a FILEHANDLE (a name you decide, all caps isn't a requirement but suggested for clarity) and a FILENAME

open(BOBSFILE, "information.txt");

The above file will be opened for "read" since no i/o type was specified. There are three ways to open a file. This is specified with a symbol before the filename. If no symbol is specified, "read" is assumed.

  1. read <            (open an existing file for read)   ex: open BOBSFILE, "<information.txt";
  2. write >            (create a new file to write)   ex: open NEWSTORY, ">story.txt";
  3. append >>            (add more to an existing file)   ex: open(LOG, ">>activity.log");

 

 

Last modified on 12 April 2008, at 10:23