in reply to Switching between output to file and STDOUT

I was going to reply with the special file "-" (as documented in perlopentut), but I found an inconsistency between 2-arg and 3-arg open. If I do this
open(OUTPUT, '>-') or die; print OUTPUT "foo\n";
I get "foo\n" on standard out. However, if I use 3-arg open like so:
open(OUTPUT, ">", '-') print "foo\n";
I get the output directed to a file called '-'. This seems like it might be a bug...can anyone point me to somewhere in the docs where this is documented behavior?

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

Replies are listed 'Best First'.
Re^2: Swiching between output to file and STDOUT
by edan (Curate) on Nov 11, 2004 at 10:31 UTC

    This seems like it might be a bug...can anyone point me to somewhere in the docs where this is documented behavior?

    Certainly. perldoc open (at least, my local pod) states:

    In the 2-arguments (and 1-argument) form opening '-' opens STDIN and opening '>-' opens STDOUT.

    It specifically declines to mention 3-arg open.

    --
    edan

Re^2: Swiching between output to file and STDOUT
by gaal (Parson) on Nov 11, 2004 at 10:46 UTC
    It isn't a bug. 3-arg open is the magicless form of the call, and is exactly what you should use when you *do* want to open a file named "-". It's a bit safer in other places too, because it doesn't make pipes of '|' characters. "../" still goes up a dir, though.