What is the best way to delete a value from an array in Perl?

前端 未结 14 2387
忘掉有多难
忘掉有多难 2020-12-12 20:17

The array has lots of data and I need to delete two elements.

Below is the code snippet I am using,

my @array = (1,2,3,4,5,5,6,5,4,9);
my $element_o         


        
14条回答
  •  Happy的楠姐
    2020-12-12 20:37

    The best I found was a combination of "undef" and "grep":

    foreach $index ( @list_of_indexes_to_be_skiped ) {
          undef($array[$index]);
    }
    @array = grep { defined($_) } @array;
    

    That does the trick! Federico

提交回复
热议问题