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

前端 未结 14 2420
忘掉有多难
忘掉有多难 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:53

    A similar code I once wrote to remove strings not starting with SB.1 from an array of strings

    my @adoSymbols=('SB.1000','RT.10000','PC.10000');
    ##Remove items from an array from backward
    for(my $i=$#adoSymbols;$i>=0;$i--) {  
        unless ($adoSymbols[$i] =~ m/^SB\.1/) {splice(@adoSymbols,$i,1);}
    }
    

提交回复
热议问题