Error when trying to print to a file and locking

R

Robert

Hi,

I am getting the following error when trying to print to a file and locking.
Browser Error:

------------------
Bareword "LOCK_EX" not allowed while "strict subs" in use at record.pl line
208.
Execution of record.pl aborted due to compilation errors.
------------------

Here is my write-to-file code:

------------------
sub record {

my $nowtime = time();
my $newentry = "$nowtime|$invoice|$fullname|$company|$emailaddy|$phone";

open (LOCKER, "<lockfile.db") or die "Can't open file: $!";
flock (LOCKER, LOCK_EX) or die "Can't lock file: $!";

open (FH, ">>records.db") or die "Can't open file: $!";
print FH "$newentry\n";
close(FH);

close(LOCKER);

}
------------------

I always use "use strict;" in my programs and have never seen this error
before. I'm not sure where to start in researching a solution. Please if you
have any thoughts please and thank you.

Robert
 
A

A. Sinan Unur

I am getting the following error when trying to print to a file and
locking. Browser Error:

Hmmm ... Have you considered reading

perldoc -f flock

especially the part:

OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly
combined with LOCK_NB. These constants are traditionally valued
1, 2, 8 and 4, but you can use the symbolic names if you import
them from the Fcntl module, either individually, or as a group
using the ':flock' tag.
------------------

Here is my write-to-file code:

------------------
sub record {

my $nowtime = time();
my $newentry =
"$nowtime|$invoice|$fullname|$company|$emailaddy|$phone";

open (LOCKER, "<lockfile.db") or die "Can't open file: $!";
flock (LOCKER, LOCK_EX) or die "Can't lock file: $!";

Have you considered reading:

perldoc -f flock

especially the part:

Note that the fcntl(2) emulation of flock(3) requires that
FILEHANDLE be open with read intent to use LOCK_SH and requires
that it be open with write intent to use LOCK_EX.

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,043
Members
48,769
Latest member
Clifft

Latest Threads

Top