in reply to Automagic Array to Hash Conversion? Pseudo-Hash Explosion

I think in your second example, your if statement is testing the wrong variable. Compare with this code:

my $foo = [ { foo => { bar => 'baz' } }, ]; foreach my $foo_entry (@$foo) { foreach (keys %$foo_entry) { if (defined($foo_entry->{$_}->{foo}) && defined($foo_entry->{$_}->{foo}->{bar})) { return $foo_entry->{$_}->{foo}->{bar} +; } } return; }

In the inner loop, $_ is a key of %$foo_entry. I'm not sure why your code passes strict, since $foo should contain an array ref and not a hash ref; I'd expect the if statement to bomb with "not a hashref".

I'm also confused about your question: Do you know the answer, and you're testing us, or have you still not figured out what's wrong?

Thanks :)

Update: On FreeBSD, perl 5.6.0, I get:

% perl hoh.pl
Out of memory during "large" request for 1073745920 bytes at hoh.pl line 15.

So, Yes it tries to gobble up lots of memory :) But luckily it fails all at once instead of eating swap and bombing the entire system.

Alan

Replies are listed 'Best First'.
Re^2: Automagic Array to Hash Conversion? Pseudo-Hash Explosion
by tadman (Prior) on May 14, 2002 at 18:33 UTC
    I mentioned that I had "fixed" it, which involved doing exactly what you pointed out. It was kind of odd that strict didn't get this one, so there were no bombs, apart from the feverish memory consumption.

    I didn't post the fix because I wanted to see if it was obvious or not, which considering it took the third reply to "solve", I suppose it really isn't.

    As a point of curiosity, does the broken example chew up all your RAM? I'm using Perl 5.6.1 on RedHat 7.2 i386 and it's swap city.