in reply to dereferencing hash within a hash within an array

Looks like you need to rethink some things...

You're looping $i 1 through $x but you're also incrementing $x! When will this loop ever end? (After carefully matching braces, I see that I was mistaken.)

Your data structure is very complex. You're trying to create an Array of Hashes of Arrays of Hashes? Or am I reading this wrong?

  • Comment on Re: dereferencing hash within a hash within an array

Replies are listed 'Best First'.
Re: Re: dereferencing hash within a hash within an array
by ihb (Deacon) on Jan 10, 2003 at 23:24 UTC
    If I understand you correctly you expect
    my $x = 10; for my $i (1 .. $x) { $x = 1; print $i; }
    to execute only once. That would be the case if the above was equivalent to
    my $x = 10; for (my $i = 1; $i <= $x; $i++) { $x = 1; print $i; }
    , but it isn't. Recall that the non-C-style for (aka foreach) is a list iterator. 1 .. $x is a list. Compare with   my @foo = 1 .. $x; If you'd now do   foreach (@foo) { ... } you wouldn't expect foreach to act any differently upon modification of $x.

    (Afaik for (EXPR .. EXPR) is nowadays optimized to not build a list, but that's irrelevant from a language point of view.)

    Hope I've helped,
    ihb
Re: Re: dereferencing hash within a hash within an array
by lpoht (Sexton) on Jan 11, 2003 at 01:41 UTC
    The final data structure is an array of hashes. In each hash is another array of hashes (each hash having only one key/value pair).