Remove an element from an array in perl

https://stackoverflow.com/questions/17216966/delete-elements-from-array-if-they-contain-some-string

CODE

my $input_Color = 'Green';
my @array = qw(Red Blue Green Yellow Black);
@array = grep {!/$input_Color/} @array;
print "@array";

KevinADC (TechnicalUser)15 Mar 05 03:49

another way without using a regexp:

CODE

my $input_Color = 'Green';
my @array = qw(Red Blue Green Yellow Black);
@array = grep {$_ ne $input_Color} @array;
print "@array";
posted on 2018-12-12 19:53  guolongnv  阅读(131)  评论(0)    收藏  举报