处理字符串文件句柄

从Perl 5.6开始,我们可以在字符串上打开一个文件句柄,操作起来和普通的文件,套接字或管道没什么两样。

1.从字符串读

my $string = <<'MULTILINE’;

Buster

Mini

Roscoe

MULTILINE



open my ($str_fh),’<’,\$string;

my @end_in_vowels = grep /[aeiou]$/,<$str_fh>;

 

2.写入字符串

my $string = q{};
open my ($str_fh),'>',\$string;

print $str_fh  "This goes into  the string\n";
posted @ 2013-04-23 15:34  新闻官  阅读(225)  评论(0编辑  收藏  举报