in reply to map and grep
In simple terms, use map for transformation and grep for filtering.
See the following code snippet
Update: Thanks to bart for pointing out that I had not closed the italics - used <i> instead of </i> for closing tag.my @ints = qw(1 2 3 4 5); my @doubleints = map { $_ * 2 } @ints; my @odds = grep { $_ % 2 } @ints; print "INTS = " . join(",", @ints) . "\n"; print "DOUBLE = " . join(",", @doubleints) . "\n"; print "ODDS = " . join(",", @odds) . "\n"; ----------- OUTPUT ------ INTS = 1,2,3,4,5 DOUBLE = 2,4,6,8,10 ODDS = 1,3,5
Mahesh
|
|---|