in reply to Problem with DBM hash of anonymous arrays

You should use strict.

You're putting values in an anonymous hash referenced by $PAHASH, while you're tying the hash %PAHASH.

Try using $PAHASH{$key}[0] etc.

Replies are listed 'Best First'.
Re^2: Problem with DBM hash of anonymous arrays
by travisbickle34 (Beadle) on May 17, 2005 at 11:38 UTC
    The PHASH isn't anonymous though, is it? It's the named handle of the DBM hash. I think :-/
      There is no "PHASH". There is a $PAHASH, which is a scalar containing a reference to an anonymous hash and there is a %PAHASH, which is a hash (tied to a dbm file), but is unrelated to $PAHASH.

      If you do $PAHASH{$something} you're refering to %PAHASH. If you do $$PAHASH{$something}, you're referering to the hash referenced by $PAHASH. This can be confusing in the beginning, I know.

      Take a look at perlreftut. But most of all, get in the habit of using strict. It'll save you from a lot of bugs.

        The way I saw it was like this:

        %PAHASH is a named hash.

        $PAHASH{key} is referring to a scalar value stored in %PAHASH.

        $$PAHASH{key}[index] is referring to a (dereferenced) scalar value, stored in an anonymous array which is a value in %PAHASH.

        This is wrong, then?

        Sorry if this seems stupid by the way...