Dear monks,

I am trying to become familiar with flock but it seems that I am getting an unexpected error:

Bareword "SEEK_END" not allowed while "strict subs"

I am searching online, and I can not found a solution to my error. The syntax looks correct but where I am going wrong?

Working sample of my code is provided below:

#!/usr/bin/perl use strict; use warnings; use Fcntl qw(:flock); $| = 1; # Flush the output my $file = "perl.txt"; open( FH , "+<" , $file ) or die "Unable to open '".$file."' - $!\n"; flock( FH , LOCK_EX ) or die "Could not lock '".$file."' - $!\n"; =notes +< open a file for updating without truncating it. (truncating means empties the file before opening it. flock exclusive lock or FH , 2 but better LOCK_EX because, might not be the right number on all operating systems. =cut seek( FH , 0 , SEEK_END ) or die "Cannot seek - $!\n"; # put the pointer at the end of file for writing. truncate( FH , 0 ) or die "Cannot truncate - $!\n"; print FH "This is line-1."\n"; print FH "This is line-2."\n"; close(FH) or die "Could not write '".$file."' - $!\n";

Well since I am asking a posting this question I hope that you do not mind to ask a few other things about flock that are not so clear to me yet.

I have read the tutorial Perl truncate Function and I am not 100% sure if I am using correctly the truncate() function.

I am confused with the part that (reduces) the size of the file. Maybe this is a very basic question and answer but I can not understand excactly what it does. I visit also truncate and a dew other wesites, but again it is not clear to me.

What I understand is that we are using it to clean the file after from the indicated point fseek() to prepate the file for writing.

Thanks everyone for the time and effort reviewing my question.

Best Regards,

Thanos


In reply to Bareword "SEEK_END" not allowed while "strict subs" in use by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.