Perl Programming/Keywords/grep

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: goto Keywords Next: gt

The grep keyword[edit | edit source]

The grep function Evaluates the BLOCK or EXPRESSION for each element of LIST by setting locally $_ to each element, and returns the list value consisting of those elements for which the expression evaluated to true. In scalar context, it returns the number of times the expression was true.

Syntax[edit | edit source]

  grep BLOCK LIST
  grep EXPRESSION, LIST
Previous: goto Keywords Next: gt