我有以下腳本:GREP獲得包含特定字符串的所有字符串
use strict;
use warnings;
my @test = ("a", "b", "c", "a", "ca");
my @res = grep(m#a#, @test);
print (join(", ", @res)."\n");
它應該僅返回包含a
字符串。它完美的作品。
問題是我需要能夠動態地獲取這些字符串。 我試過如下:
use strict;
use warnings;
my $match = "a";
my @test = ("a", "b", "c", "a", "ca");
my @res = grep($match, @test);
print (join(", ", @res)."\n");
結果是:
A,B,C,A,CA
我應該怎麼做才能夠grep
的陣列一個動態變量?