[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Updating a Tied Database



I'm trying to write a script that will change the value of a single 
field of a record in a tied database.

It works if the hash isn't tied to a file:
--
#!/usr/bin/perl -w

use strict;

my (%db, );

$db{fruit} = ({
	apple => "red",
	orange => "orange",
	banana => "yellow",
	tomato => "red"
});

$db{fruit}{tomato} = 'green';

print $db{fruit}{tomato};
--
This prints 'green'.

However, if I tie it to a file:
--
#!/usr/bin/perl -w

use strict;
use MLDBM 'DB_File';
use Fcntl;

my $dbFile = '/tmp/dbfile.txt';

my (%db, );

tie(%db, 'MLDBM', $dbFile, O_RDWR|O_CREAT, 0666)
		or die("dbopen $dbFile: $!");

$db{fruit} = ({
	apple => "red",
	orange => "orange",
	banana => "yellow",
	tomato => "red"
});

$db{fruit}{tomato} = 'green';

print $db{fruit}{tomato};

untie(%db);
--
This prints 'red'.

I must be doing something wrong. Does anyone have any ideas as to 
what it might be?
-- 
My brain hurts!
SeanC
                      Mediatek Training Institute
            129 Moore Road, Berea, Durban, South Africa
    phone: +27 (0)31 305 4200              SeanC@mediatek.co.za
      fax: +27 (0)31 305 4236
                   <http://members.xoom.com/s_carte>

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org