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


In reply to Re: Automagic Array to Hash Conversion? Pseudo-Hash Explosion by ferrency
in thread Automagic Array to Hash Conversion? Pseudo-Hash Explosion by tadman

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.