programming-examples/perl/SystemFunction/Using Map function.pl
2019-11-15 12:59:38 +01:00

13 lines
309 B
Perl

@numbers = ( 1 .. 10 );
print "\@numbers: @numbers\n\n";
# multiply every number by 2
foreach ( @numbers ) {
push( @doubledNumbers, $_ * 2 );
}
print "Double each number:\n",
"foreach: @doubledNumbers\n";
@doubledNumbers2 = map( $_ * 2, @numbers );
print "map: @doubledNumbers2\n";