File I/O in Perl
From Free Knowledge Base- The DUCK Project: information for everyone
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.
- read < (open an existing file for read) ex: open BOBSFILE, "<information.txt";
- write > (create a new file to write) ex: open NEWSTORY, ">story.txt";
- append >> (add more to an existing file) ex: open(LOG, ">>activity.log");