I have seen time and time again "don't use dbmopen because it is deprecated". I have seen people preface their posts with "I know dbmopen is deprecated and I should use tie, but this isn't my code and I need it fixed quickly", as though it was something to hide. I have seen responses to questions to "read the documentation on tie", but no concrete examples of how to do it.

Well, I am new to Perl and this was a little hard for me to swallow. I mean, it couldn't be that hard - right? Maybe - I only found one good example from a super search here, but it used DB_File, which isn't part of the core distribution. Through google searches, Perl docs, and some trial and error, I was able to come up with the following.

#!/usr/bin/perl -w use strict; use AnyDBM_File; use Fcntl; tie (my %hash, "AnyDBM_File", "filename", O_CREAT|O_RDWR, 0600) or die + "Can't open database: $!\n"; # insert code for %hash here untie %hash;

BTW - The super search results came after the trial and error since it was the exact syntax that I got a hit on.

I verified this both on ActivePerl and on a HPUX installation. Is this the most acceptable way of doing this, or is there a better way? I said maybe earlier, because it is entirely possible that I just missed something obvious.

Thanks in advance,

Limbic~Region


In reply to To tie or to dbmopen by Limbic~Region

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.