This is what I ended up using (using best guess):
sub lockread {
$ctf = $ctrdir.'ct.ctr';
open FH,"+<$ctf" or die "File could not be opened";
flock FH,2; # lock the file
$rr = <FH>; # read the file
chomp($rr);
chomp($rr);
chomp($rr);
$rr++; #incriment the file content
seek(FH,0,0); #rewind the file
truncate(FH,0); # truncate the file
print FH "$rr\n"; #write the new contents
flock FH,8; #unlock it
close FH; #close it
return $rr; #return the ID #
}
The problem is the Cookbook has a couple examples of this... except it does
not tell you whether to "unlock-and-close" or "just-close" or the improbable
"close-and-unlock" but does talk about how the lock will disolve when the
script EXITs out of memory.
FYI..Anyway.. this appears to work.
Charles Maier
CDM Consulting Services
http://www.cdmcon.com
(610) 942-2726
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
Charles Maier
Sent: Wednesday, March 14, 2001 3:17 PM
To: Perl-Win32-Web Mailing List
Subject: RE:FOLLOW-UP: Problem with UNIQUE number... task # ($$) repeats
on Novell!!!
> > As it works out... Novell's task-numbers are already like 9
> > digits.. but
> > they REPEAT (50 times in 100 calls ;o)). It looks like $$ is a time
> > variable.. possibly a seconds counter.
> >
> > Does anyone have a "bulletproof" unique id generator that
> > they would like to
> > share??
> >
> >
> > Charles Maier
> > CDM Consulting Services
> > http://www.cdmcon.com
> > (610) 942-2726
>
I got several comments.. So I want to modify/reiterate the question.
TIME will NOT work for this operation. This is because I need to ID web
accesses and these can occur simultaneously. The only way I can see this
working is using a COUNTER... with proper file locking. Since I do not quite
understand Perl's file locking.... or, more directly, how to handle failed
open on a locked file....
Could someone please illustrate a bulletproof counter solution??
Much thanks
Chuck
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web