Perl grep Function
This function extract any elements from LIST for which EXPR is TRUE.
Following is the simple syntax for this function −
grep EXPR, LIST
This function returns the number of times the expression returned true in scalar context and list of elements that matched the expression in list context.
Following is the example code showing its basic usage −Live Demo
#!/usr/bin/perl @list = (1,"Test", 0, "foo", 20 ); @has_digit = grep ( /\d/, @list ); print "@has_digit\n";
When above code is executed, it produces the following result −
1 0 20