2 issues with "tie"

T

Tuc

Hi,

I seem to be running into some issues with tie in perl 5.8.8 with the
defined-or patch from the FreeBSD ports.

I use :
use NDBM_File;
use Fcntl;

I open up my file as :
tie (%fdb,'NDBM_File',"file.victims",O_RDWR|O_CREAT,0777) ||die $!;

I write to it as
$fdb{$_}="TUC";

I close it as :
untie %fdb;

Seems pretty basic. But I've got 2 issues.

1) If $_="Fred", and the program iterates and does
$fdb{'Fred'}="TUC"; , if I immediately start another program up to
read "Fred" from the file, it claims it doesn't exist. As if it hasn't
sync'd. As soon as I do the "untie %fdb;", then the data becomes
available. Is there a way that as soon as I $fdb{'Fred'}="TUC"; it
becomes accessible?

2) I also have the issue that if I'm running my program, and I hit
CNTRL-C to stop it, none of the values I've $fdb{$_}="TUC"; end up
getting and staying set. So the next time the program runs, and checks
to see if its already in the data store, it says its not and re-
executes the command. Is there some way that once its set its
"committed" per se?

Thanks, Tuc
 
C

comp.llang.perl.moderated

I seem to be running into some issues with tie in perl 5.8.8 with the
defined-or patch from the FreeBSD ports.

I use :
use NDBM_File;
use Fcntl;

I open up my file as :
tie (%fdb,'NDBM_File',"file.victims",O_RDWR|O_CREAT,0777) ||die $!;

I write to it as
$fdb{$_}="TUC";

I close it as :
untie %fdb;

Seems pretty basic. But I've got 2 issues.

1) If $_="Fred", and the program iterates and does
$fdb{'Fred'}="TUC"; , if I immediately start another program up to
read "Fred" from the file, it claims it doesn't exist. As if it hasn't
sync'd. As soon as I do the "untie %fdb;", then the data becomes
available. Is there a way that as soon as I $fdb{'Fred'}="TUC"; it
becomes accessible?

NDBM doesn't appear to have a 'sync' method to
force a flush to disk. I don't know if there's
a convenient workaround so, alternatively, you
may want to consider using DB_File which does
provide a 'sync'.

DB_File also has other advantages and doesn't
have have NDBM's key,value length max.
2) I also have the issue that if I'm running my program, and I hit
CNTRL-C to stop it, none of the values I've $fdb{$_}="TUC"; end up
getting and staying set. So the next time the program runs, and checks
to see if its already in the data store, it says its not and re-
executes the command. Is there some way that once its set its
"committed" per se?

You could set up an signal handler to catch
the interrupt and untie, eg.,

$SIG{INT} = sub { untie %fdb; };
 
B

Ben Morrow

Quoth "comp.llang.perl.moderated said:
NDBM doesn't appear to have a 'sync' method to
force a flush to disk. I don't know if there's
a convenient workaround so, alternatively, you
may want to consider using DB_File which does
provide a 'sync'.

DB_File also has other advantages and doesn't
have have NDBM's key,value length max.

Under FreeBSD, <ndbm.h> is in fact implemented with <db.h> anyway, so
switching to DB_File should leave you still able to read your old
databases.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top