MLDBM Problems 
Author Message
 MLDBM Problems

I am storing multi-level hashes and arrays using the MLDBM module.

I tie the data to a hash %records

I have a function which stores or updates data within %records

I have a all my data in a 160M file data_file.db

If I run my function and update this file, trying to add new records,
some of them seem not to go in.

If I run the function against a new file (created as we go) all the
data goes in.

I have spent some time trying to solve this problem but am now stuck.

Are their any suggestions about whats wrong? or any knwon issues with
MLDBM.

my data structure is:

A hash: key - value

where the value is an array ref $a_ref

$a_ref[0] # a scalar
$a_ref[1] # a hash ref $h_ref

$href     # hash with (scalar) keys but no values

Thanks...
M



Sun, 31 Jul 2005 22:27:51 GMT  
 MLDBM Problems


Quote:
>I am storing multi-level hashes and arrays using the MLDBM module.
>I tie the data to a hash %records
>I have a function which stores or updates data within %records
>I have a all my data in a 160M file data_file.db
>If I run my function and update this file, trying to add new records,
>some of them seem not to go in.
>If I run the function against a new file (created as we go) all the
>data goes in.
>I have spent some time trying to solve this problem but am now stuck.
>Are their any suggestions about whats wrong? or any knwon issues with
>MLDBM.

A standard debugging technique for you to try is to whittle your code
down to the smallest example that shows the behaviour that you've
mentioned, and then show us that.

Without seeing your code, my only guess is that you're trying to reach
into the "value" side of an MLDBM record and manipulate it directly.  
Because MLDBM doesn't allow that, you need to do something like this:

my $tmp = $tied_mldbm_hash{$key};
$tmp->{thing}->{other_thing} = "new value";
$tied_mldbm_hash{$key} = $tmp;

...Steve

--
Steve van der Burg
Technical Analyst, Information Services
London Health Sciences Centre
London, Ontario, Canada



Sun, 31 Jul 2005 23:20:19 GMT  
 MLDBM Problems


Quote:
> I am storing multi-level hashes and arrays using the MLDBM module.

> I tie the data to a hash %records

> I have a function which stores or updates data within %records

> I have a all my data in a 160M file data_file.db

> If I run my function and update this file, trying to add new records,
> some of them seem not to go in.

> If I run the function against a new file (created as we go) all the
> data goes in.

> I have spent some time trying to solve this problem but am now stuck.

> Are their any suggestions about whats wrong? or any knwon issues with
> MLDBM.

> my data structure is:

> A hash: key - value

> where the value is an array ref $a_ref

> $a_ref[0] # a scalar
> $a_ref[1] # a hash ref $h_ref

> $href     # hash with (scalar) keys but no values

MLDBM recognizes the change and updates the stored data if it detects a
change in the hash - this means in the first level of values, the
references.  

Example: if %h is

   A => reference to {z => 'Z', w => 'W'}
   B => 'five',
   C => reference to ['pit', 'pat, 'put'],

                ^^^                  ^^^
           change detected      change not detected

The solution is to force recognition of the change.  One method is to
create the complete value as a temporary variable, modify, and then assign
it.  For example, $temp = $h{C]; $temp->[1] = 'pet'; $h{c] = $temp; instead
of $h{C}[1] = 'pet';

--
EBC



Sun, 31 Jul 2005 23:49:56 GMT  
 MLDBM Problems

Quote:


> >I am storing multi-level hashes and arrays using the MLDBM module.
> >I tie the data to a hash %records
> >I have a all my data in a 160M file data_file.db
> >If I run my function and update this file, trying to add new records,
> >some of them seem not to go in.
> >If I run the function against a new file (created as we go) all the
> >data goes in.
> A standard debugging technique for you to try is to whittle your code
> down to the smallest example that shows the behaviour that you've
> mentioned, and then show us that.

The problem doesn't seem to be just with updating existing records,
but adding new ones.
If I tie to a new file, the data goes in, if I tie to the existing
160MB file it seems not to. (or at least I can't see it when I try to
get it out again)

Could the problem be related to some bad key values?
I had heard there was once an issue with some keys containing the q's
as it was interpreted as the perl func. (don't know any more about
this)
Are there any character I can't have in my key strings? If so is there
funtions to escape/un-escape them?

Thanks for the interest so far!

Ok here's the trimmed down bit of code:

#start of code snippets
use MLDBM qw( DB_File );        # database file interaction
use Fcntl;                      # imports c-style definitions e.g. O_RDWR

tie( my %thread_data, 'MLDBM', $index_file, O_CREAT|O_RDWR, 0666 ) or
        die "Error - Unable to open '$index_file': $!\n";

# sub to index a file
sub store_data{

  #retrieve parent & child data for this node_id
  my $a_ref = $tree_data{ $node_id };  

  #if its new initialise it
  unless( defined( $a_ref ) ){
        $tree_data{ $node_id } = $a_ref = [ "-"];
  }

  # assign parent's id to position 0 in array
  $a_ref->[0] = $parent;

  # store parent
  $tree_data{ $node_id } = $a_ref;      

  # add this node to list of children for the parent

  #retrieve parent & child data for parents_id
  $a_ref = $tree_data{ $parent };              

  # initialise if new
  unless( defined $a_ref ){
        $tree_data{ $parent } = $a_ref = [ '-' ];      
  }

  #add node_id to parents list of children
  $$a_ref[1]{$node_id} = "";          

  #store parents data
  $tree_data{ $parent } = $a_ref;      

Quote:
}#end sub

#end of code


Mon, 01 Aug 2005 19:37:34 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. MLDBM problem

2. MLDBM Problem and Fix

3. Newbie: MLDBM problem...

4. Newbie: MLDBM problem...

5. Q: Problem with MLDBM

6. Problems w/MLDBM

7. problem compiling with MLDBM

8. Problems with MLDBM-modul, databasefile growing with duplicates

9. Problem with MLDBM Module

10. Problem with Storable and MLDBM

11. Problem installing MLDBM 2.00

12. PROBLEM: data output w/MLDBM

 

 
Powered by phpBB® Forum Software