On Tue, Jul 17, 2001 at 06:43:14PM -0400, Jared Chenkin wrote:
> I'm kinda rusty on my perl..had to work in java for a while =(
> How do you take a multidimensional hash such as $hash{$key1}{$key2}{$key3} and write 
>it
> to a database file without too much of a headache?  

    use MLDBM qw(DB_File Storable);
    use Fcntl qw(O_RDWR O_CREAT);

    tie(%hash, "MLDBM", "file.db", O_RDWR|O_CREAT) || die("tie: $!");

Unfortunately, you have to change how you assign to the hash, from:

    $hash{$key1}{$key2}{$key3} = "foo";

to
    my $tmp = $hash{$key1};
    $$tmp{$key2}{$key3} = "foo";
    $hash{$key1} = $tmp;

Accesses don't need to change, though.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to