hi all,

i wonder whether some of you encountered the same error and can point me to what's going wrong.

i'm trying to use a gdbm file for storage of large and complex data structures. funny enough, writing them doesn't make any problem, but when i'm trying to read the previously stored data, GDBM_File.pm dies without giving me a reason. When i ran the code step by step under perldb, at one time there was an error message "Bad file descriptor" - but that was not reproducable. here's the code:

package Foo::DBM; use strict; use vars qw /$VERSION @ISA/; $VERSION = 1.0; use Exporter; @ISA = qw/Exporter/; use GDBM_File; use Storable qw/freeze thaw/; sub new { my ($class, $path, $type, $key) = @_; my $self = { PATH => $path, TYPE => $type, KEY => $key, RECORD => { +} }; bless $self, $class; $self->read if $key; $self; } sub read { my $self = shift; die "Can't read without knowing what" unless $self->{KEY}; my $filename = "$self->{PATH}/$self->{TYPE}"; $filename =~ s/\/\//\//g; my %file; tie %file, 'GDBM_File', $filename, GDBM_READER || die $!; my $rec = $file{$self->{KEY}}; $self->{RECORD} = thaw $rec; untie %file; 1; } sub save { my $self = shift; die "Can't write without knowing where" unless $self->{KEY}; my $filename = "$self->{PATH}/$self->{TYPE}"; $filename =~ s/\/\//\//g; my %file; tie %file, 'GDBM_File', $filename, GDBM_WRCREAT, 0640 || die $!; my $rec = freeze $self->{RECORD}; $file{$self->{KEY}} = $rec; untie %file; 1; } 1;

the line producing the code is in sub read{} and tunes:tie %file, 'GDBM_File', $filename, GDBM_READER || die $!;

i have no idea at all how to solve this problem, so any clues will be appreciated. many thx in advance.

Janitored: <readmore> tags added by davido.


In reply to GDBM_File dies without telling why by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.