########################################################################
sub get_next_file_number {
# 'shift' to obtain the pathname we sent
my($path_to_index) = shift;
# If 'index' doesn't exist, create it and
# write a '0' and 9 spaces into it
# (explained below)
if (!-e "$path_to_index/index")
{
open (INDEX,">$path_to_index/index") or die "eek! -- index";
if (defined INDEX)
{
print INDEX "0 ";
close (INDEX) or die "eek! can't close Index(1)";
}
}
# Open for reading. We're looking for a 10-position
# numeric with trailing spaces -- a format of index
# numbering PowerWeb uses. On my machine, PowerWeb's
# POP server is what will finally deliver the mail
# to my mail reader (and to other users' programs).
# We'll read the number and increment it...
open (INDEX,"<$path_to_index/index") or die "eek! -- index";
if (defined INDEX)
{
while (<INDEX>)
{
/(\d+)\s/; # field is 10-chars wide, trailing-space padded
$newcount = $1 + 1;
}
close (INDEX) or die "eek! can't close Index(2)";
}
# ...and then write it back into the index file
# and 'return' it to the calling program code.
open (INDEX,">$path_to_index/index") or die "eek! -- index";
if (defined INDEX)
{
print INDEX sprintf("%-10s","$newcount");
close (INDEX) or die "eek! can't close Index(3)";
}
return $newcount;
}