Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Open an existing DB_Ffile file failed (http://www.velocityreviews.com/forums/t902682-open-an-existing-db_ffile-file-failed.html)

panxd01@gmail.com 04-14-2007 01:03 AM

Open an existing DB_Ffile file failed
 
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.



All times are GMT. The time now is 02:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.