http://www.perlmonks.org?node_id=1085523

thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:

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