|
Posted by xhoster on May 12, 2005, 4:41 pm
Please log in for more thread options
> Ok fair enough, just wondering really if I was doing something
> fundamentally wrong in what I was trying to achieve. Anyway here's
> make, read and delete mini scripts.
>
> Run the make and in another window delete one of the keys entered
> during the make, hence the sleep to give you time to run the delete.
>
> make:
> use LockFile::Simple qw(lock unlock);
> use Tie::Persistent;
>
> my %DB;
> tie %DB, 'Tie::Persistent', '/tmp/file.PD', 'rw';
> while(<main::DATA>){
> chomp;
> lock('/tmp/file.PD');
##tie needed here
> $DB = 1;
> (tied %DB)->sync;
## untie needed here.
> unlock('/tmp/file.PD');
> print "Added <$_> sleeping for 2\n";
> sleep 2;
> }
> untie %DB;
The loop only writes the private data out to disk each time through the
loop, it never reads the disk data back into memory, so never notices that
the other method changed the data on the disk.
Since there doesn't seem to be a reverse-sync method, what you would need
to do is tie and untie the hash inside the loop instead of outside it.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
|