bobo has asked for the wisdom of the Perl Monks concerning the following question:

i have @open array which I tied with Tie::array...
i fill that array with objects, but i don't think that's the problem...
anyway...
before spliceing i have in @open objects with ids {102001, 103002, 100001, 101002, 103001, 99000, 102000, 103003, 99001, 100002} (array is sorted by other object data).
after

for my $i(0..$#open){ if ($open[$i]->id==$node->id){ my $bla = splice @open, $i, 1; print "i=$i\t"."id=".$bla->id."\n"; last; } }

perl writes out "i=6 id==102000" (which is correct id i was looking for and correct index of object with that id)
and i get in @open object with ids {102001, 103002, 100001, 101002, 103001, 99000, 102000, 103003, 103003}
what went wrong? :(

Replies are listed 'Best First'.
Re: Tie::array and splice
by almut (Canon) on Apr 01, 2010 at 09:51 UTC

    On a side note, when you're thinking of Tie::Array::Sorted, please do say so, not "Tie:array".  Although Tie::Array::Sorted uses Tie::Array as a base class, they differ considerably in their area of use...  which made it quite hard to make sense of your original question.

Re: Tie::array and splice
by jethro (Monsignor) on Apr 01, 2010 at 08:38 UTC
    The code you show works as intended. I just tried it with a normal array. That means the bug is in code you didn't show, probably your implementation of the tied functions
      only functions i use with this part of code are getters for my objects, and they are working fine in other parts of code, so i don't think they are the problems...
      only other thing that could be wrong (or at least i don't have idea what else could interfere with this) is my sorting subroutine... but it's too simple to be wrong (or is it?)...
      i did tieing like this:
      tie @open, "Tie::Array::Sorted", sub { $_[0]->f <=> $_[1]->f };
      that function (f) is just another getter for my objects... also works fine in the rest of the code... subroutine is almost exactly as one in description of Tie::array::sorted on CPAN...
      code is pretty big so i'd like to avoid posting it here because i don't think anything outside this block of code (except those functions i mentioned) could mess things up... :/
      if you have some idea where i could look for errors, it would be really helpfull... :)
      p.s. now i see it could be the ::sorted part that i should have mentioned earlier... :$
        code is pretty big so i'd like to avoid posting it here

        Compose a minimal, self-contained example that exhibits the same problem, and post that here.

        As this would allow the Monks to reproduce the issue without having to do your work for you (or having to guess), you'll likely get better help that way.