Question d’entretien chez Booking.com

Perl's grep and map function

Réponse à la question d'entretien

Utilisateur anonyme

5 juill. 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);