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

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-10 13:46:47

select the filehandle not use the default STDOUT;
  1. open FILE, ">log.txt" or die "cannot open $!";
  2. select FILE;
  3. $| = 1;
  4. print "this is to log";
  5. select STDOUT;
  6. print "this is to stdout\n";
after change the filehandle, better to change back.
$| special variable is flush the buffer.

Perl 5.10 borrows the say built-in from the ongoing development of Perl 6 (which may
have borrowed its say from Pascal’s println). It’s the same as print, although it adds
a newline to the end. These forms all output the same thing:
use 5.010;
print "Hello!\n";
print "Hello!", "\n";
say "Hello!";
This is especially handy in the common case of simply wanting to put a newline after whatever you want to output:

To interpolate an array, you still need to quote it though. It’s the quoting that puts the
spaces between the elements:
use 5.010;
my @array = qw( a b c d );
say @array;   # "abcd\n"
say "@array"; # "a b c d\n";
Just like with print, you can specify a filehandle with say:
use 5.010;
say BEDROCK "Hello!";


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