in reply to Remove array elements dynamically!

Use an array slice
delete @array[@arrayindex];

Replies are listed 'Best First'.
Re^2: Remove array elements dynamically!
by Joost (Canon) on Aug 27, 2007 at 19:50 UTC
Re^2: Remove array elements dynamically!
by newbio (Beadle) on Aug 27, 2007 at 19:52 UTC
    Hello FunkyMonk, Thanks for your reply. I understand "delete" function simply removes t +he value and does not change the index. However, what I want is to re +move the value along with its index (like what splice function does). + Thus imho, I guess delete will not help here? Any other solution? Th +anks, delete @array[@arrayindex];
      It may be too inefficient if your arrays are large, but it does what you ask.
      my @array = 1 .. 10; my @arrayindex = ( 2, 6, 4, 5 ); splice @array, $_, 1 for sort { $b <=> $a } @arrayindex; print "@array\n"; # 1 2 4 8 9 10

      Thanks to Joost and newbio for pointing out that an aray slice doesn't delete elements not at the end of an array.