Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I am writing a program where i sometimes have to redirect STDOUT. When i want to restore it I use the following code

open ($oldout,'>&',\*STDOUT);

I found this on the internet and it works fine, but i don't know what '>&' means exactly. I've been going through my documentation but i can't find anything. Can someone explain why the & sign needs to be there? ty.

Replies are listed 'Best First'.
Re: rerouting STDOUT
by LanX (Saint) on May 20, 2013 at 04:41 UTC
    It's bourne shell syntax for duplicating a filehandle.

    After

    open ($oldout,'>&',\*STDOUT);

    $oldout is a copy of STDOUT, which can now be safely closed or redirected and later restored by reversing the copy.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re: rerouting STDOUT
by vinoth.ree (Monsignor) on May 20, 2013 at 04:38 UTC

    You will find the answer from perldoc perldoc:open


    All is well