I have a banner impression counter.
But when I try to lock the counter file the script doesn't
work. What I am doing wrong?
use Fcntl qw(:flock); # import LOCK_* constants
if ( -e $file_banner)
{
open(COUNT,"$file_banner") || die print "Could not open for read";
# flock(COUNT,LOCK_EX) || die print "Could not lock";
$line = <COUNT>;
# flock(COUNT,LOCK_UN) || die print "Could not unlock";
close(COUNT);
print "a:$line";
$line++;
print "b:$line";
open(COUNT,"+< $file_banner") || die print "Could not open for wri
+te";
# flock(COUNT,LOCK_EX) || die print "Could not lock";
print COUNT "$line";
# flock(COUNT,LOCK_UN) || die print "Could not unlock";
close(COUNT);
}
else
{
open(NEW,"> $file_banner");
print NEW "0";
close(NEW);
print "ffff\n\n";
}
exit;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.