in reply to Re: Remove array elements dynamically!
in thread Remove array elements dynamically!

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];

Replies are listed 'Best First'.
Re^3: Remove array elements dynamically!
by FunkyMonk (Bishop) on Aug 27, 2007 at 20:22 UTC
    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.