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:
The following things do work making me think my data structure is ok:# old and busted my $record = $db{some_key}; $record->[2] += 100; $db{some_key} = $record; # new hotness $db{some_key}[2] += 100;
#!/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;
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 | |
by gctaylor1 (Hermit) on Jun 24, 2009 at 00:15 UTC | |
by Anonymous Monk on Oct 23, 2012 at 21:42 UTC |