in reply to Re: Perl eats all memory when accessing hash/array refs wrong
in thread Perl eats all memory when accessing hash/array refs wrong

The problem is that you are using a reference as index in an array.

I admit that this appears to be whats going on, But I do not understand how. I see no lookup of an array in that code.

Heres some toying I did with the problem.

#!perl -l use strict; use warnings; my $a = {child1 => [ {child2 => [ {child3 => [ {child4 => [1]} ]} ]} ] +}; print $a->{child1}{child2}{child3}; #cut off {child3} and no problem. print '$a:',ref $a; print '$a->{child1}:',ref $a->{child1}; print '$a->{child1}{child2}:',ref $a->{child1}{child2}; print '@{$a->{child1}}:',scalar @{$a->{child1}}; __END__ $a:HASH $a->{child1}:ARRAY $a->{child1}{child2}:HASH @{$a->{child1}}:28004977

So it would appear that somehow $a->{child1}{child2} is being treated as an array lookup. But how? There is no array lookup involved.

Id be interested to hear an explanation as to why this isnt a bug in perl.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re: Re: Re: Perl eats all memory when accessing hash/array refs wrong
by Anonymous Monk on Sep 25, 2003 at 12:11 UTC
    Pseudo-hashes are an experimental and soon-to-be-deprecated feature.

      Aha! Thanks very much. It wasn't obvious to me that this was a pseudo-hash lookup, but now that you point it out its quite clear. And from this example alone its a Good Thing that they are going to go away. Any array containing a hash as the 0 element gets magically treated as a pseudo hash. The fog clears....

      At the very least the pseudo-hash code should insist that the hash is composed of ONLY integer values, and certianly should NOT silently numerify the array ref. It should throw a fatal error there IMO. Anyway, we all know thats not going to happen, as they well be disappearing soon enough, but what an oversight.

      *sigh* and thanks. Good eye.


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi