PDA

View Full Version : Who understands dbmopen vs. tie?


Stephen
02-22-1999, 12:46 AM
I have a problem understanding how to save associative arrays to file on this system. I'm relatively new to perl and a real tyro when it comes to perl AND Unix. I've been learning perl on Win95 and using the dbmopen function to save my hashes. However, that doesn't appear to work here.

Instead of creating .dir and .pag extension dbm files I'm getting .db extensions on the FQ server. So here's my question: what do other users do to save hashes to file here? I want to be able to use the same function on Win95 as here under Unix (or Linux, or whatever it may be). Should I be using the tie package (as in the Tie::Hash module)? At the moment that's all I can see that might be cross-system compatible. I don't understand tie() yet, so I thought I'd ask how others handle this problem before turning my attention to figuring the in's and out's of a new module.

Thanks,
Stephen

Terra
02-22-1999, 01:16 AM
dbmopen() is deprecated in favor of Tied Hashes...

Depending upon what you bind TIE() to will determine the extensions... We can currently handle NDBM_File / GDBM_File / SDBM_File / DB_File...

TIE() is a perl builtin, and interfaces with the above modules...

I generally use the NDBM for simple stuff, and DB hashes for more complicated B-Tree methadology... I am in the process of coverting all my system programs over to MySQL... http://www.aota.net/ubb/wink.gif

I ((think)) what you are using on Win95 is 'SDBM', but not sure as I don't use the Win95 port... I would read the cross-platform compatibility page...

BTW: Writing a hash converter is rather trivial...
Pseudo Code:
use in-dbm-module;
use out-dbm-module;

Tie(IN-dbm)
Tie(OUT-dbm)

while IN-dbm { write OUT-dbm }
close Tie(*[IN && OUT]*)

--
Terra
--Using hash incorrectly can cause brain faults--
FutureQuest

[This message has been edited by ccTech (edited 02-22-99).]

Stephen
02-22-1999, 08:12 PM
Terra's right. SDBM comes with the standard Win32 distribution. By using the SDBM_File module and Fcntl to formulate the O flags that the tie() needs for instruction on how to treat the stored hash I seem to be able to at least do simple hash storage. So I'm happy!

[This message has been edited by Stephen (edited 02-22-99).]