好奇心驱使下,是否可以在Perl脚本中创建、实例化或以其他方式访问除STDOUT和STDERR之外的其他输出缓冲区?
使用案例是将附加输出导入到文件或其他命令中,例如./doublerainbow.pl 3>full_on.txt 4>all_the_way!.txt
>&=
模式的open
命令可以在任意文件描述符上打开文件句柄。# perl 4fd.pl > file1 2> file2 3> file3 4> file4 5< file5
open NONSTDFOO, '>&=3';
open NONSTDBAR, '>&=4';
open NONSTDBAZ, '<&=5'; # works for input handles, too
print STDOUT "hello\n";
print STDERR "world\n";
print NONSTDFOO "42\n";
print NONSTDBAR <NONSTDBAZ>;
$ echo pppbbbttt > file5
$ perl 4fd.pl >file1 2>file2 3>file3 4>file4 5<file5
$ cat file1
hello
$ cat file3
42
$ cat file4 file2
pppbbbttt
world
STDFOO
,那么整个 "std" 的意义就会被贬低。 :) - hobbs>&
dup
(创建一个新的文件描述符)并从新的文件描述符创建一个Perl文件句柄。您应该使用>&=
为现有的文件描述符创建一个Perl句柄。已修复。 - ikegami