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

Monks,

I'm trying to use MLDBM::Easy so I can update a value in a HoA without having to use a temporary variable, but the value is not updated. The perldoc for MLDBM::Easy says:

This module allows you to work with multi-dimensional databases, just like MLDBM, but it does work behind the scenes to allow you to treat the multi-dimensional database like a normal data structure. Basically, you don't need to use the piecemeal access that MLDBM required:

# old and busted my $record = $db{some_key}; $record->[2] += 100; $db{some_key} = $record; # new hotness $db{some_key}[2] += 100;
The following things do work making me think my data structure is ok: Here's my simple example:
#!/usr/bin/perl use strict; use warnings; use MLDBM::Easy; use Fcntl; my %hash; tie (%hash, 'MLDBM', 'testmldbm', O_CREAT|O_RDWR, 0640) or die $!; $hash{value1} = [ '0', '1', '2' ]; # assign anonymous array print "@{$hash{value1}}[0, 1, 2]\n"; $hash{value1}[2] += '1'; # add/modify element 2 untie %hash; tie (%hash, 'MLDBM', 'testmldbm', O_RDWR, 0640) or die $!; print "@{$hash{'value1'}}[0, 1, 2]\n"; untie %hash;

Which yields the following output:

0 1 2
0 1 2

It seems like I must be doing something wrong!? Any suggestions?

Thank-you.

Replies are listed 'Best First'.
Re: MLDBM::Easy does not update data structure
by Anonymous Monk on Jun 23, 2009 at 06:42 UTC
    Don't you want to tie MLDBM::Easy
    |||||| VVVVVV tie (%hash, 'MLDBM', 'testmldbm',
      I made the change  tie (%hash, 'MLDBM::Easy', 'testmldbm', O_CREAT|O_RDWR, 0640) or die $!; as suggested but that produced another error.
      Can't use string ("") as a SCALAR ref while "strict refs" in use at bl +ah.pl line 12.
      Line 12 is print ${$hash{value1}}[2], "\n";

      I've tried a few different things but am not sure how to resolve. Is the problem how I'm trying to print it or is it the assignment? If I comment out the print line, the assignment seems to work (no error message).

      What confuses me more, I didn't get this error with tie (%hash, 'MLDBM'

        Did you find the answer to your question? I still get the same error you mentioned above

        Can't use string ("") as a SCALAR ref while "strict refs" in use at