Perl Programming | ||
---|---|---|
List Operators | ||
my @primes = (2, 3, 5, 7, 11, 13, 17, 19); my @doubles = map {$_ * 2} @primes; print "The doubles of the primes are: @doubles\n"; my @small = map {$_ < 10 ? $_ : ()} @primes; # grep {$_ < 10} @primes print "The primes smaller than 10 are: @small\n"; The doubles of the primes are: 4 6 10 14 22 26 34 38 The primes smaller than 10 are: 2 3 5 7 |
||
Previous | http://www.mit.edu/iap/perl/ | Next |