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. | [reply] [d/l] |