Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RE: RE: Array mysteriously disappears on loop exit...

by Anonymous Monk
on Oct 09, 2000 at 19:31 UTC ( [id://35920]=note: print w/replies, xml ) Need Help??


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

Sorry about the formatting - I'm terrible at reading instructions...
The array does actually contain stuff just prior to the last statement, as it's in the debug output, but I don't know where it goes afterwards.
Is there any strange behaviour in perk that I'm not aware of - I'm using perl 5.004_04 on Solaris.
Prior to the call to get_parentRelPos there are many calls to this:
sub add_containee(\%\%) { my ($container, $containee)=@_; #$container/containeeIndex are references to code providing this infor +mation #find the container my ($object, $i); my $found=0; for ($i=0; $i< @containerRefArray; $i++) { if ($containerRefArray[$i] eq $container) { $found=1; last; } } if (! $found) {push @containerRefArray, $container; push @containeeArray, []} if (defined $containee) { push @{$containeeArray[$i]}, $containee;} }

Replies are listed 'Best First'.
(Guildenstern) REx3: Array mysteriously disappears on loop exit...
by Guildenstern (Deacon) on Oct 09, 2000 at 19:51 UTC
    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!
      @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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://35920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-16 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found