Newbie Question

Ken Loomis kloomis at
Sat Aug 12 15:01:32 CDT 2000

I just started learning Perl and found the San Diego Perl Mongers group.
Trying to re-arrange my schedule to make it to this month's meeting, but I
have a challenge today that I need some help that I would be most
appreciative of.

I use a small data file to keep the Customer_ID number in. Each time a new
customer registers, I increment the number in that file. However, we are
getting so many requests, that at time the number gets reset to 1. I am
pretty sure this is because of the way the flock works.

I checked out the FAQ's and found this code segment for handling this:

    use Fcntl;
    sysopen(FH, "numfile", O_RDWR|O_CREAT)       or die "can't open numfile:
    flock(FH, 2)                                 or die "can't flock numfile:
    $num = <FH> || 0;
    seek(FH, 0, 0)                               or die "can't rewind
numfile: $!";
    truncate(FH, 0)                              or die "can't truncate
numfile: $!";
    (print FH $num+1, "\n")                      or die "can't write numfile:
    close FH                                     or die "can't close numfile:

I ran a test of this from one domain that I host and it worked fine. However
when I incorporated it into the client's CGI that collects the customer info,
I get an error.

Here is the code segment as I placed it into the CGI:

    sysopen(FH, "/www/htdocs/freetitandslcom/CustomerID.dat",
O_RDWR|O_CREAT)     or &safe_die("Can't open CustomerID.dat file");
    flock(FH, 2)                               or &safe_die("can't flock
CustomerID.dat: $!");
    $newcustomerid = <FH> || 0;
    seek(FH, 0, 0)                             or &safe_die("can't rewind
CustomerID.dat: $!");
    truncate(FH, 0)                            or &safe_die("can't truncate
CustomerID.dat: $!");
    (print FH $newcustomerid+1, "\n")                    or &safe_die("can't
write CustomerID.dat: $!");
    close FH                                   or &safe_die("can't close
CustomerID.dat: $!");

The error I get is:

    can't truncate CustomerID.dat: Permission Denied

As a shot in the dark, I tried setting the permission on the "CustomerID.dat"
file to '766' but that had no effect.

I am now searching the FAQ's for "Permission Denied" but was hoping someone
out there could point me in a narrower direction.

Thanks in advance for any help.

Ken Loomis

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kloomis.vcf
Type: text/x-vcard
Size: 333 bytes
Desc: Card for Ken Loomis
Url :

More information about the San-Diego-pm mailing list