Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Storable and MLDb

by saintex (Scribe)
on Nov 17, 2010 at 23:21 UTC ( #872090=perlquestion: print w/ replies, xml ) Need Help??
saintex has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I have a problem with Storable and MLDb... substantially, because I have not confidence with these modules.

I use a mailing list software that I love, but I have a problem with data format.
This software store data not with a RDBM database, but using MLDb and Storable.

I need to create a connector (I can: this software is Open Source) in order to connect it to my personal website, but I'm not able to manipulate data with those two modules.

Ok, I go to the code,
That software use:
use Fcntl qw( O_WRONLY O_TRUNC O_CREAT O_CREAT O_RDWR O_RDONLY LOCK_EX LOCK_SH LOCK_NB); use MLDBM qw(AnyDBM_File Storable);
and these are some rows, the software use to store data:
my $dbm = tie %{$self->{DB_HASH}}, 'MLDBM', $self->_db_filename, O_CRE +AT|O_RDWR, FILE_CHMOD
then with that row, it read the file:
sysopen(DB_SCHEDULE_SAFETYLOCK, $self->_lockfile_name, O_RDWR|O_CREAT +, FILE_CHMOD )
I think these are all the rows involved in data storage.
If you are interesting in, the modules are these ones:

MLDb.pm
Schedules.pm

I need to read the generated files, in order to write or append there some data.

I tried in several way to read that file, but without success.
For example with:
use MLDBM qw(AnyDBM_File Storable); use Storable qw(retrieve_fd); use Fcntl qw (:DEFAULT :flock); use FindBin qw($Bin); tie (%hash, "MLDBM", $Bin.'mj-test-schedules', O_CREAT|O_RDWR, 0666) or die $!; # sysopen(DB_SCHEDULE_SAFETYLOCK, $Bin.'/mj-test-schedules', O_RDW +R|O_CREAT, 0666); #open FILE, ">", $Bin.'/filename.txt' or die $!; open (DF,$Bin.'/mj-test-schedules') or die $!; flock (DF, LOCK_SH) or die $!; $href=retrieve_fd(*DF); close DF; while ( my ($key, $value) = each(%$href) ) { print "$key => $value\n"; } #print FILE $_ while (<DB_SCHEDULE_SAFETYLOCK>) ; #close FILE; untie %hash;
In addition I don't understand (and that is probably the problem) what MLDb does and how Storable and MLDb work together.
Please, someone can help me?
Thank you very much.

Comment on Storable and MLDb
Select or Download Code
Re: Storable and MLDb
by tokpela (Chaplain) on Nov 18, 2010 at 19:25 UTC

    If you are looking at saving data to disk in a hash structure, my recommendation is to use DBM::Deep.

    It's pure Perl, fast and very stable.

    use strict; use warnings; use DBM::Deep; my $dbm = DBM::Deep->new('mj-test-schedules'); $dbm->{'some_key_name'} = 'some value'; for (keys %$dbm) ) { print "$_ => $dbm->{$_}\n"; }

      I tried your code, but unluckily I have:
      DBM::Deep: Signature not found -- file is not a Deep DB at prova2.pl line 6 Br />

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://872090]
Approved by sweetblood
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-09-23 01:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls