Sollicitatievraag bij Booking.com

Perl's grep and map function

Antwoord op sollicitatievraag

Anoniem

5 jul 2015

grep is a filter, and returns the original list item if the expression test was true ex : my @arr = grep { $_ > 2; } (1, 2, 3); #@arr ==> (3) map : return the expression from map block to a new array ex : my @arr = map { $_ > 2; } (1, 2, 3); #@arr ==> ('','',1);