-1

How to remove matching elements from the array? Let say I have array @A [1, 2, 2, 3, 4, 4, 4, 5] and now I have remove element 2 and 3 so I should see @A [ 1, 4, 4, 4, 5] only in the array.

mpapec
  • 50,217
  • 8
  • 67
  • 127
user1595858
  • 3,700
  • 15
  • 66
  • 109

1 Answers1

4

You can use grep to filter out elements you don't want:

my @A    = (1, 2, 2, 3, 4, 4, 4, 5);
my @newA = grep { $_ != 2 } @A; 
# @newA has elements (1,3,4,4,4,5)
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170