Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

open a gdbm file

by lakssreedhar (Acolyte)
on Oct 27, 2012 at 06:01 UTC ( [id://1001165]=perlquestion: print w/replies, xml ) Need Help??

lakssreedhar has asked for the wisdom of the Perl Monks concerning the following question:

I want to open a gdbm file.I tried the below code but cant open file error message is displayed

#!/usr/bin/perl -w use strict; use DB_File; my (%HASH, $key, $val); my $filename = "/home/DESKTOP/dict_final"; tie %HASH, 'DB_File', $filename, O_RDWR, 0666, $DB_HASH or die "Can't +open $filename: $!\n"; while (($key, $val) = each %HASH) { print "$key::$val\n"; }

Replies are listed 'Best First'.
Re: open a gdbm file
by Athanasius (Archbishop) on Oct 27, 2012 at 06:25 UTC
    I want to open a gdbm file.

    From the documentation, it appears that the DB_File module cannot be used with gdbm files:

    DB_HASH

    This database type allows arbitrary key/value pairs to be stored in data files. This is equivalent to the functionality provided by other hashing packages like DBM, NDBM, ODBM, GDBM, and SDBM. Remember though, the files created using DB_HASH are not compatible with any of the other packages mentioned.

    Try the GDBM_File module instead.

    Hope that helps,

    Athanasius <°(((><contra mundum

Re: open a gdbm file
by Khen1950fx (Canon) on Oct 27, 2012 at 06:44 UTC
    I think that you were thinking of something like this:
    #!/usr/bin/perl BEGIN { $| = 1; $^W = 1; } use strict; use autodie; use warnings; use GDBM_File; my (%hash, $key, $val); my $filename = "/home/DESKTOP/dict_final"; tie %hash, 'GDBM_File', $filename, &GDBM_READER, 0640; while (($key, $val) = each %hash) { print "$key::$val\n"; } untie %hash;
      @Khen1950fx

      i could read the file thanks for the code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1001165]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2024-04-23 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found