start page | rating of books | rating of authors | reviews | copyrights

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: Reference: goto Chapter 5
Function Reference
Next: Reference: hex
 

grep

grep 
expr
, 
list
 grep {
block
} 
list

Evaluates expr or block in a Boolean context for each element of list , temporarily setting $_ to each element in turn. In list context, it returns a list of those elements for which the expression is true. Mostly used like Unix grep where expr is a search pattern, and list elements that match are returned. In scalar context, grep returns the number of times the expression was true.

For example, presuming @all_lines contains lines of code, this example weeds out comment lines:

@code_lines = grep !/^#/, @all_lines;


Previous: Reference: goto Perl in a Nutshell Next: Reference: hex
Reference: goto Book Index Reference: hex