Domanda di colloquio di Booking.com

Perl's grep and map function

Risposta di colloquio

Anonimo

5 lug 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);