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

前端 未结 14 2414
忘掉有多难
忘掉有多难 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条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 20:47

    Is this something you are going to be doing a lot? If so, you may want to consider a different data structure. Grep is going to search the entire array every time and for a large array could be quite costly. If speed is an issue then you may want to consider using a Hash instead.

    In your example, the key would be the number and the value would be the count of elements of that number.

提交回复
热议问题