Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Open an existing DB_Ffile file failed

Reply
Thread Tools

Open an existing DB_Ffile file failed

 
 
panxd01@gmail.com
Guest
Posts: n/a
 
      04-14-2007
Hi, I tried to open an existing DB_File type of file to read the
records. However, it kept getting error saying "cannot open file: File
exists". Did some research on web but couldn't find any useful info.
Could someone please explain why? Below is a sample of code which I
got from the perl.com:

use strict ;
use DB_File ;
use vars qw( %h $k $v ) ;

tie %h, "DB_File", "fruit", O_RDWR|O_CREAT, 0640, $DB_HASH
or die "Cannot open file 'fruit': $!\n";

# Add a few key/value pairs to the file
$h{"apple"} = "red" ;
$h{"orange"} = "orange" ;
$h{"banana"} = "yellow" ;
$h{"tomato"} = "red" ;

# Check for existence of a key
print "Banana Exists\n\n" if $h{"banana"} ;

# Delete a key/value pair.
delete $h{"apple"} ;

# print the contents of the file
while (($k, $v) = each %h)
{ print "$k -> $v\n" }

untie %h ;

When I second time run the code, I got into the error because 'fruit'
was created before. My perl version is 5.8.8 if this makes difference.
Thanks a lot.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot open user default database. Login failed. Login failed for user 'HEMPC\ASPNET' Tony Johansson ASP .Net 3 01-02-2010 04:09 PM
Existing Dll - using Functions from an existing dll Tristin.Colby@gmail.com Ruby 0 02-05-2008 07:38 PM
Why no existing Java type to existing XML schema binding support? nrm Java 3 04-10-2006 04:52 PM
open an existing file Regina Java 6 11-18-2005 08:35 AM
Error Installing 'termios' [ld: fatal: file crt1.o: open failed: No such file or directory] x1 Ruby 0 10-30-2005 06:50 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57