代码之家  ›  专栏  ›  技术社区  ›  Aakash Goel

如何使用Perl执行反向grep?

  •  4
  • Aakash Goel  · 技术社区  · 14 年前

    相当于什么 grep -v 在Perl?

    代码看起来像这样

    @files = reversegrep(/^[ ]+$/, @files);
    

    我想要 @files 列出所有非空文件名。

    1 回复  |  直到 14 年前
        1
  •  15
  •   Eugene Yarmash    14 年前

    可以在表达式或块中使用否定:

    @files = grep !/^\s+$/, @files;
    

    perldoc grep .