Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

(Guildenstern) RE: Array mysteriously disappears on loop exit...

by Guildenstern (Deacon)
on Oct 09, 2000 at 19:10 UTC ( [id://35914]=note: print w/replies, xml ) Need Help??


in reply to Array mysteriously disappears on loop exit...

First of all, use the CODE tags:
package myPackage; my @containerRefArray=(); my @containeeArray=(); ... sub get_parentRelPos (\%$) { my ($object, $name)=@_; my ($i, $j, $found); my @tmp; my $parentObject=$object->{'~PARENT'}; my $objectIndex=$object->{'~entPhysicalIndex'}; for ($i=0; $i < @containerRefArray; $i++) { if ($containerRefArray[$i] eq $parentObject) { $found=1; last; } } ...

Second - based on the code you've given with no other info, it's obvious why your array is empty. I can only assume that somewhere in the snipped portion of your code do you actually do something with @containeeArray, because I don't see it used at all in the code example. Are you using it as a parameter to get_parentRelPos?
We need more info before we can help!

Update: Hmmm...Apparently somebody edited the top level node and added CODE tags...

Guildenstern
Negaterd character class uber alles!

Replies are listed 'Best First'.
RE: RE: Array mysteriously disappears on loop exit...
by Anonymous Monk on Oct 09, 2000 at 19:31 UTC
    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;} }
      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>
RE: RE: Array mysteriously disappears on loop exit...
by Anonymous Monk on Oct 09, 2000 at 19:33 UTC
    You can ignore the comments in the above code about container/containeeIndex being references to code - I changed it since then

Log In?
Username:
Password:

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

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

    No recent polls found