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.
Asked
Active
Viewed 455 times
-1

mpapec
- 50,217
- 8
- 67
- 127

user1595858
- 3,700
- 15
- 66
- 109
-
http://search.cpan.org/perldoc?List%3A%3AUniq – Kevin Panko Nov 26 '13 at 01:48
1 Answers
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
-
Can I store the modified output in the same array like @A = grep {$_ !=2 } @A ? – user1595858 Nov 25 '13 at 20:31