> > I'm learning as best I can using every book orielly makes.  I am 
> > trying to saved a complex data structure (hash). I'm trying to use 
> > Berkly DBFile and tie. I am unable to store the file ie 
> retrieve info 
> > once I have exited the program.  Once I tie a hash toe the  file 
> > access the contents should be the same as accessing the contents of 
> > the hash
> 
> What have you done so far? If you had posted your code or a 
> snippet of it 
> we can help you better. Here is a small example.


I added a snippet below.

################### CODE SNIPPET ###################
sub db_write {

    my (
        %COMPANY_DB,
        %COMPANY_DBT);

    # connecting hash to data file - note this routine is to be improved
at a later date
    #############################################
    tie (%COMPANY_DB,'MLDBM','studio3.db',O_RDWR|O_CREAT,0777,$DB_BTREE)
|| die $!;                                                   
    #############################################
    # derive neccessary update location
    ############################################
    my ($option)=$_[0];
    my ($hash_no)=$_[1];
    my ($hash_info)=$_[2];
    my $name;
    print "debug \n sub db_write recieved option $option\n";
    if ($option == 1) {
        $COMPANY_DB{employee} ->[$hash_no] = $hash_info;
        $name= $COMPANY_DB{employee} -> [$hash_no] -> {info} -> [0] ->
{first};
        print "debug\n" . $COMPANY_DB{employee} -> [$hash_no] -> {info}
-> [0] -> {first} . "\n";
        print "you updated $name" . "'s info.\n";
    }



 You might 
> also want to 
> take a look at flock (perldoc -f flock). 
> 
> #!/usr/local/bin/perl -w
> use strict;
> use DB_File;
> 
> my ($tiedb, %tied_hash);
> $tiedb = tie (%tied_hash, 'DB_File', 'tie_example.db', 
> O_CREAT|O_RDWR, 0666) or
>     die "dbcreat tie_example.db failed : $!\n";
> # Once you exit from the program you will have to tie again 
> to access the 
> # values. My guess is you are not doing this.
> 
> foreach (keys (%tied_hash)) {
>     print "$_ ---> $tied_hash{$_}\n";
> }
> 
> while (<STDIN>) {
>     chomp;
>     $tied_hash{$_} = $_;
> }
> $tiedb->sync;
> undef ($tiedb);
> untie ($tiedb);
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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

Reply via email to