Linux/Perl: Additional output buffers other than STDOUT and STDERR?

前端 未结 1 1891
一向
一向 2021-01-02 12:21

Out of curiosity, is it possible to create, instantiate, or otherwise access additional output buffers besides STDOUT and STDERR from within a Perl script?

The use c

相关标签:
1条回答
  • 2021-01-02 12:53

    Absolutely. The open command with the >&= mode allows you to open filehandles on arbitrary file descriptors.

    # 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
    
    0 讨论(0)
提交回复
热议问题