处理字符串文件句柄

从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";

你可能感兴趣的:(字符串)