#!/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
";
}
#!/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
";
}