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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
猜你喜欢
  • 2022-12-23
  • 2021-07-09
  • 2021-08-09
  • 2021-09-04
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案