www.perl.com
Perl Programming
List Operators
  • grep
    • Similar to the Unix command grep
    • Finds matching items in the list
    • Matches usually based on a regular expression or a comparison

        my @juices = qw(apple cranapple orange grape apple-cider);
        my @apple = grep(/apple/, @juices);
        print "These juices contain apple: @apple\n";

        my @primes = (2, 3, 5, 7, 11, 13, 17, 19);
        my @small = grep {$_ < 10} @primes; # $_ is each element of @primes
        print "The primes smaller than 10 are: @small\n";
      

        These juices contain apple: apple cranapple apple-cider
        The primes smaller than 10 are: 2 3 5 7
      
Previous http://stuff.mit.edu/iap/perl/