Okay. Well, what errors are you getting? Could you post them? The solutions the other posters posted should work, at least with a little tweaking for your own purposes. It's true that some may not work if you just copy them verbatim.

I'd second (or third, or fourth) the responses recommending a hash tied to a DBM file. Were those the samples you had trouble with? A DBM file associates keys with values and provides fast access to searching for those keys. They provide a functionality very similar to (exactly the same as?) Perl's associative arrays--which, I presume, is why Perl uses associative arrays to access DBM files.

There are several different DBM packages, and there are pros and cons to the different solutions. To read more about the different packages that you can use, look at the AnyDBM_File manpage. SDBM_File was recommended by another poster because it comes with Perl and thus should automatically be on your system. If you start doing more work with tie and DBM files, you may want to investigate the DB_File module, because it's much more robust. However, I don't believe it comes with Perl.

In the context of DBM files, the tie function is used to bind an associative array to the DBM file. When you use the associative array--for example, when you write something like

my $value = $hash{$key};
--this (eventually) invokes the routine in the DBM library that looks up a value in the DBM. Essentially, what you're doing is hiding the DBM implementation behind a simple associative array; and in general, this is what tie does-- it hides a more complicated implementation behind a simple Perl variable (be it a scalar, an array, an associative array, or, according to perltie, a filehandle).

Sorry if this is redundant, i.e. you already knew much of this stuff; but I thought it might be helpful for you in trying to figure out what's going on, and why people are suggesting that you use tie.

As to your particular problem, I suggest that you post the error messages that you're getting; then perhaps we can determine what's going wrong.


In reply to RE: Re: Wondering novice... by btrott
in thread Wondering novice... by threepts

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.