When you stepped through with the debugger, did you confirm that the call to Foo::DBM->new() provided correct values for the PATH and TYPE args? Did you check the value of $filename before using tie? And if that value was as expected, did you check that the file(s) actually exist?

Does the failure in the read() call happen in the same calling program that used the save() call? (I trust you are making sure to save something to the file before trying to read it...)

Sorry, no answers yet, just questions. That's because I don't see anything wrong with the code as it stands. Maybe I would add parens around the args in the tie call, and use "or die" instead of "|| die", just to make sure there isn't any confusion about precedence (e.g. just in case the GDBM_READER constant is defined as "0", which means that the last arg to tie would be parsed as "GDBM_READER || die", which would evaluate to the return value of the "die" call -- not what you want).

Update: having seen the first reply (posted while I was writing this one), it's plausible that adding the extra permission arg (which would always evaluate to true) before the "|| die" works because it's another way of decoupling "GDBM_READER" and "|| die". If this is the case, that "die" call might never get invoked as a result of a failed return from tie. I'd still suggest using parens and "or die".

Another update: sure, you can just add parens around the tie args, or just switch from "|| die" to "or die" -- either step by itself would be sufficient. But you need to do at least one of them if you want that "die" trap to really work as intended.


In reply to Re: GDBM_File dies without telling why by graff
in thread 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.