Perl finding all number bigger than 10

In this example we want to filter all elements bigger than 10, for that we use grep like in this function:

#!/usr/bin/perl
use strict;
#example data
my @array = (2, 17, 10, 9, 16, 3, 9, 16, 5, 1, 17, 14);
#filter elements
@array = bigger_than_10(@array);
#print 
print "@array";
#function
sub bigger_than_10 {
return grep $_ >= 10, @_;
}

We got this as result:

17 10 16 16 17 14

Leave a Reply

Your email address will not be published.

ten + eight =