Re: splicing and empty rows



muppet wrote:
you actually need to do this:

  sub del_user {
      my $bywhat = shift;
      for (0   {$UserList->{'data'}}-1) {
          if ($UserList->{data}[$_][1] eq $bywhat) {
              splice @{$UserList->{'data'}}, $_, 1;
              last; # stop!
          }
      }
      update_busers();
  }

in general, if you need to modify the list while traversing it, and may be removing elements, either traverse it from back to front, or start over after every modification.
Thanks for explanation and code. That worked fine!


--
Sincerely, ArtÅras 'arturaz' Ålajus
You can find me at:
irc.freenode.org: nick arturaz
irc.data.lt: nick arturaz
ICQ: 157929934
Jabber: arturaz akl lt




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]