|
Everything is pretty
straight forward when it comes to saving. Notice the file
handle of the opened file "FILE" in the print statement of
the text being saved. Here is a piece of sample code:
- open (FILE, ">file.txt");
- print FILE "Text
To be saved\n";
- close(FILE);
The above saving code
works nice for one time jobs, but what if you want to add
a few items to a already started list? The below code will
show you how to append to a file:
- open (FILE, ">>file.txt");
- print FILE "Text
To be saved\n";
- close(FILE);
Take
note of the ">>" located near the filename. This tells
perl to open the file for input, and sets the output to append
to the file. If you forget to put two <<'s you will
write over the file.
|