Chinaunix首页 | 论坛 | 博客
  • 博客访问: 836308
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-18 15:43:58

  1. my @data = (4.75, 1.5, 2, 1234, 6.9456, 12345678.9, 29.95);
  2. 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 {}.
  1. 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.

  1. my %hash = map { $_, 3 * $_ } @input_numbers;
we can get a hash .



阅读(390) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~