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

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-10 10:13:44

  1. while (<>) {
  2.   chomp;
  3.   print "It was $_ that I saw!\n";
  4. }
diamond operator will automatically open and close a series of files for you, or read from the standard-input stream if there aren’t any filenames given.

with the argument file "test.txt", "a.txt", "b.txt". it will ouput all lines of the three files. without break. the current file name stored in $ARGV.
 If you find yourself
putting two diamonds into the same program, especially using the second diamond
inside the while loop that is reading from the first one, it’s almost certainly not going
to do what you would like.* In our experience, when beginners put a second diamond
into a program, they meant to use  $_ instead. Remember, the diamond operator
reads the input, but the input itself is (generally, by default) found in $_.

the diamond operator reads from @ARGV. so we can force the @ARGV to change the files.





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