Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Creating dbm files with perl

by sherab (Scribe)
on Apr 14, 2014 at 14:35 UTC ( [id://1082248]=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks!
I am migrating an older set of routines to AWS from Solaris. The code itself uses dbm files (.pag and .dir) and generates them via "makedbm" which is on the Solaris box that I am migrating from (it's a regular cron job). The new AWS is CentOS which doesn't have makedbm and I can't seem to find any source for makedbm. I know that it's easy for perl to open dbm files, but can perl generate the .pag and .dir files needed? I'm looking to just replace the Solaris "makedbm" with a perl routine if possible.

Replies are listed 'Best First'.
Re: Creating dbm files with perl
by sherab (Scribe) on Apr 14, 2014 at 14:58 UTC
    Making a set of files....
    dbmopen(%pets, "C:/temp/petFile", 0644) || die "Cannot open petFile"; $pets{cat} = "Mao"; $pets{dog} = "Spot"; dbmclose(%pets);
    Accessing DBM files....
    dbmopen(%pets, "C:/temp/petFile", 0644) || die "Cannot open petFile"; while(($animal, $name) = each %pets) { print "the name of my $animal is $name\n"; } dbmclose(%pets);
Re: Creating dbm files with perl
by CountZero (Bishop) on Apr 14, 2014 at 17:47 UTC
    Of course, the dbmopen function will make all necessary files as needed.

    The documentation for dbmopen says:

    This binds a dbm, ndbm, sdbm, gdbm, or Berkeley DB file to a hash. HASH is the name of the hash. (Unlike normal open, the first argument is not a filehandle, even though it looks like one). DBNAME is the name of the database (without the .dir or .pag extension if any). If the database does not exist, it is created with protection specified by MASK (as modified by the umask).

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Creating dbm files with perl
by sherab (Scribe) on Apr 14, 2014 at 14:52 UTC
    Note: I am pretty sure that dbmopen is the answer I have been seeking. I'll update this thread with an example as soon as I get one working. Just in case someone has this question in the future.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-24 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found