I see what you mean. All that code that I am using came directly from the book CGI Programming with Perl , Chapter 10, Section 2 ("DBM Files"). I am not very experienced with file locking, and I wasn't really interested in the syncronization stuff when we covered it in my OS class (semaphores still send shivers up my spine). I figured I could just copy and paste the code from the book to get it to work, but I guess I was wrong.

So how do you suggest I deal with file locking? As explained in the book, the point of the $db variable is to get the file descriptor. Once that is done, we 'undef' it to decrement the reference count. That way, when hash is untie'd, the changes made to hash are committed to the file. But I guess instead of doing all that, I can use a different file as a lock?

I still find it peculiar that things work when there is a Dumper call in hash_init that reads the values. Can anybody explain why that happens?

Also, can you tell me what you had to change in the code that I posted? Because that really is what I am using..


In reply to Re^4: Proper way of passing around tie'd variable by graffitici
in thread Proper way of passing around tie'd variable by graffitici

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.