Linux / Perl:除STDOUT和STDERR以外的其他输出缓冲区?

出于好奇,是否可以创build,实例化或以其他方式访问除了STDOUT和STDERR之外的其他输出缓冲区?

用例可以是input文件或其他命令的附加输出,例如./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 STDFOO, '>&=3'; open STDBAR, '>&=4'; open STDBAZ, '<&=5'; # works for input handles, too print STDOUT "hello\n"; print STDERR "world\n"; print STDFOO "42\n"; print STDBAR <STDBAZ>; 

 $ 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