in reply to NDBM_File won't store data

I tested the principle with this code and it worked fine
use NDBM_File; use Fcntl; tie (%mtime, "NDBM_File",'mtime',O_RDWR|O_CREAT|O_EXCL, 0640) or die " +error : $!"; # dump the data for (sort keys %mtime){ print "$_ $mtime{$_}\n"; } # add a new key $date= MakeDate(); $now = scalar localtime; $mtime{$now} = $date; untie %mtime; sub MakeDate { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me(time); $year = ($year + 1900) ; $mon++ ; my $date = sprintf("%04D%02d%02d", $year, $mon, $mday); return $date; }
How are you checking the values in the database ?
poj

Replies are listed 'Best First'.
Re: Re: NDBM_File won't store data
by HamNRye (Monk) on Aug 28, 2003 at 21:27 UTC

    The report function returns nothing. When I read the flat-file, it has aerio_sx_02_c.epsabrewster_pam.epsbbrewster_pam.eps in there. I should see keyvaluekeyvalue not just keykeykey.

    I myself wrote a test function:

    # testing Functions sub NDBM_test { my $date = MakeDate(); #write my %test; tie %test, "NDBM_File", 'test', O_RDWR|O_CREAT|O_EXCL, 0644; foreach $number (1...10) { $test{$number} = $date; } untie %test; #read tie %test, "NDBM_File", 'test', O_RDWR|O_EXCL, 0644; foreach $number (1...10) { print "$number: $test{$number}\n"; } untie %test; }

    And it produces:

    1: 20030828 2: 20030828 3: 20030828 4: 20030828 5: 20030828 6: 20030828 7: 20030828 8: 20030828 9: 20030828 10: 20030828

    Here's what the flat file looks like...

    2003082810200308289200308288200308287200308286200308285200308284200308 +283200308282200308281
      I'm not sure what you mean by 'the report function' or 'the flat-file', are you referring to another piece of code ? To confirm the problem is in the database, run your test code against the database thus ;
      #read tie %test, "NDBM_File", 'mtime', O_RDWR|O_EXCL, 0644; foreach (keys %test) { print "$_: $test{$_}\n"; } untie %test;
      If this shows only keys, try it with the other database 'type'.
      #read tie %test, "NDBM_File", 'type', O_RDWR|O_EXCL, 0644; foreach (keys %test) { print "$_: $test{$_}\n"; } untie %test;
      If the 'type' db is storing strings OK but the 'mtime' db is not, I give up !
      poj

        As wierd as this may sound, never use mtime with NDBM_File. I did a replace and replaced every instance of "mtime" with "index", and the program works fine.