Keep only list values that match a condition.

Grep Filter

grep_filter.pl
use strict;
use warnings;

my $minimum = ;
my @scores = (2, 3, 5, 8);
my @kept = grep { $_ >= $minimum } @scores;
my $count = scalar @kept;
my $joined = join(",", @kept);

print "minimum=$minimum\n";
print "count=$count\n";
print "kept=$joined\n";
use strict;
use warnings;

my $minimum = ;
my @scores = (2, 3, 5, 8);
my @kept = grep { $_ >= $minimum } @scores;
my $count = scalar @kept;
my $joined = join(",", @kept);

print "minimum=$minimum\n";
print "count=$count\n";
print "kept=$joined\n";
grep-filter Grep returns the list items that pass a test. The original list is unchanged.