in reply to RE: RE: Array mysteriously disappears on loop exit...
in thread Array mysteriously disappears on loop exit...

Okay, I can see now how you're getting stuff into @containeeArray. I'm still not sure where you're using this. Is it a parameter to get_parentRelPos? I would assume not, since it looks like it should take a hash reference ans a scalar, not an array. Aside from populating the array, tell us how it's used.
Also, it looks to me like your debugging output references a line that says if ($found) {, which I don't see aywhere in the code you posted. (If I'm wrong here, somebody let me know!). Maybe if you posted the code that contains that line?

Guildenstern
Negaterd character class uber alles!
  • Comment on (Guildenstern) REx3: Array mysteriously disappears on loop exit...
  • Download Code

Replies are listed 'Best First'.
RE: (Guildenstern) REx3: Array mysteriously disappears on loop exit...
by Anonymous Monk on Oct 09, 2000 at 20:14 UTC
    @containeeArray is a hash of hashes containing references to the same kind of hashes as in @containerRefArray. After I get the index of the container containing %$object, in following code I look up the corresponding entry in @containeeArray. I then sort the hash in $containeeArray$i and then return the position in this sortted hash of %$object.

    That was the plan anyway.

    Here's the rest of the fns

    <CODE> sub sort_objects { $a->{'~entPhysicalIndex'} <=> $b->{'~entPhysicalIndex'}; } sub get_parentRelPos (\%$) { my ($object, $name)=@_; my ($i, $j, $found); my (@tmp, $dummy); my $parentObject=$object->{'~PARENT'}; my $objectIndex=$object->{'~entPhysicalIndex'}; if (ref $parentObject ne 'HASH') { confess "parent object wasn't a hash"; return -1; } for ($i=0; $i < @containerRefArray; $i++) { if ($containerRefArray$i eq $parentObject) { $found=1; last; } } if ($found) { # Call the code in each contained object to obtain the entPhysicalIndex of each one and then sort them (references in containeeArray point to tied hashes) # 1: # sorting with sort sort_objects @{$containeeArray$i} didn't work for some reason ?? # 2: # @tmp=@{$containeeArray$i}; # 3: # foreach $dummy (@{containeeArray$i}) { # push @tmp, $dummy; # } # none of the above 3 methods seem to work right @tmp = sort sort_objects @tmp; for ($j=0; $j < @tmp; $j++) { if ($tmp$j eq $object) { return $j+1; } } } return -1; } <\CODE>
      Okay. I'm pretty sure I haven't found out why yuor array is empty. I did notice some other stuff in your code and explanation.
      Are you sure @containeeArray is a hash of hashes? It looks more to me like it's an array of hashrefs.
      # sorting with sort sort_objects @{$containeeArray$i} didn't work for some reason ??Not sure here, but it seems to me like the value if $i may not be what you think it is. Plus, if @containeeArray really is an array of hashrefs, this code shouldn't work. I would try something like sort sort_objects @containeeArray instead.

      Guildenstern
      Negaterd character class uber alles!