perl中grep函数的使用

#!/usr/bin/perl
@spam=("bat","cat","dath","datg");
if (my $lines=grep {/dat/}@spam){#再标量上下文中,grep返回的是匹配到的个数
print "$lines ";
}
@spam2=("bat","cat","dath","datg");#再列表上下文中,grep返回的是匹配到的字符串列表
if (my @lines=grep {/dat/}@spam2){
print "@lines ";
}

原文地址:https://www.cnblogs.com/shunguo/p/11397097.html