-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
  • 49,466
  • 8
  • 63
  • 119
user1595858
  • 3,426
  • 12
  • 60
  • 102

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
  • 56,682
  • 21
  • 115
  • 164