Error when trying to print to a file and locking

Discussion in 'Perl Misc' started by Robert, Feb 23, 2006.

  1. Robert

    Robert Guest

    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
    Robert, Feb 23, 2006
    #1
    1. Advertising

  2. "Robert" <> wrote in
    news:kd7Lf.61549$sa3.48710@pd7tw1no:

    > 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.


    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

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 23, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Praveen
    Replies:
    1
    Views:
    729
    Kevin Yu [MSFT]
    Apr 16, 2005
  2. Timasmith
    Replies:
    4
    Views:
    438
    Bjorn Borud
    Nov 1, 2006
  3. keto
    Replies:
    0
    Views:
    884
  4. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    330
    David Cournapeau
    Dec 30, 2008
  5. Ludwigi Beethoven
    Replies:
    5
    Views:
    309
    Mike Hall
    Jul 26, 2003
Loading...

Share This Page