8.22. grep

Example 8-16. examples/arrays/grep_perl.pl

#!/usr/bin/perl
use strict;
use warnings;

my @numbers = (1..30);
my @odd_numbers = grep { $_ % 2 } @numbers;
foreach my $num (@odd_numbers) {
    print "$num\n";
}


If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed