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

Hello! I'm looking for something similar to $| = 1 to flush out the memory before untie takes place. Please advise. Thanks
. . tieFile(); . . LOOP: until($pktype eq 'EOJ') { . . while($agntsock->recv($pkstr, $MAXLEN)) { . . my $oldfilehdl = select(%mmResource); $| = 1; $mmResource{$mmKey} = join('|', ($timeframe, $currentDay, $startTi +me, $endTime, $mmRec)); select($oldfilehdl); . . } . . } sub tieFile { my $sr = 'tieFile'; my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( +time); my $resource = sprintf("ResourceMM_%02d%02d%02d%02d.dbm", $mday, $ho +ur, $min, $sec); tie %mmResource, "DB_File", $resource, O_RDWR|O_CREAT, 0640, $DB_HAS +H or die "Cannot open file $resource: $!\n"; $beslog->pnl($sr, 4, "tie file, $resource\n"); }
Everytime this line is executed, $mmResource{$mmKey} = join('|', ($timeframe, $currentDay, $startTime, $endTime, $mmRec)); the size of my DB_FILE is not increasing unless I do an untie, is there a way to make it write out to the flat file right away without having to untie it?

Replies are listed 'Best First'.
Re: size of .dbm file of hash table not growing
by ehdonhon (Curate) on Nov 27, 2002 at 22:07 UTC

    If you look at the DB_File Perldoc, you will see there is a method named sync(). I believe it will do what you are looking for.

      Yes, sync() did the trick. Thanks so much for your help.