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

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-10 11:04:33

there are also six special filehandle names that Perl already uses for its own pur-
poses: STDIN, STDOUT, STDERR, DATA, ARGV, and ARGVOUT.

open CONFIG, "dino";
open CONFIG, "open BEDROCK, ">fred";
open LOG, ">>logfile";

The first one opens a filehandle called CONFIG to a file called dino. That is, the (existing)
file dino will be opened and whatever it holds will come into our program through the
filehandle named CONFIG.

The second does the same as the first, but the less-
than sign explicitly says “use this filename for input,” even though that’s the default.

a greater-than sign means to createa new file for output. This opens the filehandle  BEDROCK for output to the new file fred.

The fourth example shows how two greater-than signs may be used (again, as the shell
does) to open a file for appending. That is, if the file already exists, we will add new
data at the end. If it doesn’t exist, it will be created in much the same way as if we had used just one greater-than sign.

In modern versions of Perl (starting with Perl 5.6), you can use a “three-argument” open:
open CONFIG, "<", "dino";
open BEDROCK, ">", $file_name;
open LOG, ">>", &logfile_name();

close BEDROCK;
阅读(311) | 评论(0) | 转发(0) |
0

上一篇:print printf %${width}s

下一篇:die $!

给主人留下些什么吧!~~