Chinaunix首页 | 论坛 | 博客
  • 博客访问: 838760
  • 博文数量: 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:56:57

  1. my @names = qw{ zero one two three four five six seven eight nine };
  2. my @numbers =  @names [ 9, 0, 2, 1, 0 ];
  3. print "Bedrock @numbers\n"; # says Bedrock nine zero two one zero

  1. my $new_home_phone = "555-6099";
  2. my $new_address = "99380 Red Rock West";
  3. @items[2, 3] = ($new_address, $new_home_phone);

  1. my @three_scores = ($score{"barney"}, $score{"fred"}, $score{"dino"});
  2. the same with
  3. my @three_scores = @score{ qw/ barney fred dino/ };

When you see something like @score{ ... } in a Perl program, you’ll need to do just as Perl
does and look at the at sign at the beginning as well as the curly braces at the end. The
curly braces mean that you’re indexing into a hash; the at sign means that you’re getting
a whole list of elements, not just a single one .
  1. @score{ @players } = @bowling_scores;
  2. print "Their scores were: @score{@players}\n";


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