To read a file, we use the open command again, just a little different than before
01: open (WEBCOUNTER,"<webcounter.txt") || die "Cannot open file";
02: $webcounts = <WEBCOUNTER>;
03: close(WEBCOUNTER);
Now this works fine if we have a file with only one line. Please note that you can assign any handle here, instead of WEBCOUNTER you could simply use FILE of anything else. Just make sure it's the same whenever you the filehandle (line 2!). Now let's see how we read a file with multiple lines:
01: open (WEBCOUNTER,"<webcounter.txt") || die "Cannot open file";
02: for (<WEBCOUNTER>)
03: {
04: print $_;
05: }
03: close(WEBCOUNTER);
Quite easy too I would say. But would if would like to store the content in an array? Look at this:
01: open (WEBCOUNTER,"<webcounter.txt") || die "Cannot open file";
02: @webcounter = <WEBCOUNTER>;
03: close(WEBCOUNTER);
And that's this. Now let's write to a file, you have already seen how that works by the way ...