On Wed, 12 Apr 2017 16:19:32 -0400 Uri Guttman <u...@stemsystems.com> wrote:
> On 04/12/2017 04:08 PM, Илья Рассадин wrote: > > Hi! > > > > You can use splice to delete elements from array. > > > > To delete multiple elements you need to do splice in a loop > > > > my @indices = qw/2 4 5 7/; > > why are you using qw which makes strings and not a list of integers? Because you don't have to type all those commas. ;) > > > > > my @array; > > > > for my $index (reverse sort @indices) { > sort defaults to a lexical sort which won't work well on integers > with more than 2 digits. > > and why are you sorting and reversing the indexes? i don't think that > will help make the splice more efficient if any of the indexes are > not at the end of the array. If you're going to splice, do it from the highest index to the lowest. Otherwise the splice will shift the end of the array down, which messes up the indexing. > > > splice @array, $index, 0; > > > > > you need a length of 1 to remove the element. that line is a no-op. > > uri > -- Don't stop where the ink does. Shawn H Corey -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/