P
panxd01
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.
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.