- my @data = (4.75, 1.5, 2, 1234, 6.9456, 12345678.9, 29.95);
-
my @formatted_data = map { &big_money($_) } @data;
The map operator looks much like grep because it has the same kind of arguments: a
block that uses $_, and a list of items to process. And it operates in a similar way,
evaluating the block once for each item in the list, with $_ aliased to a different original
list element each time. But the last expression of the block is used differently; instead
of giving a Boolean value, the final value actually becomes part of the resulting list.
modify the items in array according to the expression in {}.
- perl -le 'my @data = (4.75, 1.5, 2, 1234, 6.9456, 12345678.9, 29.95);print "The money numbers are:\n",map { sprintf("%25s\n",$_ )} @data;'
to format the value in the @data.
- my %hash = map { $_, 3 * $_ } @input_numbers;
we can get a hash .
阅读(446) | 评论(0) | 转发(0) |