in reply to Tricking a filename argument to use STDOUT

The /dev/fd/1 trick works on Linux:

use strict; use warnings; sub hello { my $filename = shift; open my $out, '>', $filename or die "Can't write to $filename: $!\n"; print $out "Hello world!\n"; close $out or die "Failure closing $filename: $!\n"; return; } hello( '/dev/fd/1' ); # use /dev/fd/1 as the filename for STDOUT print "Is STDOUT still open?\n"; __END__ Hello world! Is STDOUT still open?

the lowliest monk

Replies are listed 'Best First'.
Re^2: Tricking a filename argument to use STDOUT
by cazz (Pilgrim) on Jun 27, 2005 at 21:41 UTC
    Basically the same idea, /dev/stdout works in many OSs. In whatever flavor of linux I'm using at the time (don't know, don't care) /dev/stdout is a link to /proc/self/fd/1.