here is the source code...

The theme of today is:

Name
Do you like NyQuil Yes   No
How many times have you taken NiQuil today?
Comments
So...this tells us.

to open a file, use the command
open (FILE, "file.txt");

where FILE is just a variable name (note: no $). file.txt is replaced by the name of whatever file it is you are opening. the statement above opens a file for reading. to write a new file, it would be

open (FILE, ">file.txt");

and to append to the end of the file, it would be
open (FILE, ">>file.txt");

when you are done with whatever you are doing to the file, close it:

close FILE;

where FILE is again the variable name.

to loop line by line through a file you are reading, you can put it in a while loop like this:

while ($record = ) the variable $record (which you can call whatever you like), stores the current line of the file. the while loop halts when there are no lines left in the file to read.

if you have formatted data (ie a bunch of fields separated by ::), you can break that data into pieces. if there is the line

Joe::Shmoe::111-11-1111

you can get the different fields into their own variables using the split command:

($first_name, $last_name, $ssn) = split ("::", $record);

where "::" is whatever the delimiting character(s) are, and $record is the variable storing the line. the three variables in () on the left will store the values. split breaks the data wherever your delimiting characters are, and assigns them in order to the variables on the left. if you have fewer varaibles than data items which are split up, the first data items will get assigned to varaibles, and the rest just get lost.

to write out to a file, we use the print statement, almost like normal:

print FILE "whatever you are printing";


The inclass examples