#!/perl/bin/perl

# access.pl
#
# First version.  Creates or opens a file with a number
# in it, increments the number, writes it back.

    $CountFile = "counter.dat";    # Name of counter file.

# Open the file and read it.  If it doesn't exist, its "contents"
# will be read into a program variable as "0".

    open (COUNT, $CountFile);
    $Counter = <COUNT>;            # Read the contents.

# Close the file, then reopen it for output.

    close (COUNT);
    open (COUNT, ">$CountFile");

# Increment $Counter, then write it back out.  Put up a message
# with the new value.  Close the file and exit.

    $Counter += 1;
    print COUNT $Counter;
    print "$CountFile has been written to $Counter times.\n";
    close (COUNT);

#                    End access.pl
