From: Adriano Rodrigues Ferreira <[EMAIL PROTECTED]>
> When using FileHandles as the object-oriented wrapper for file
> handles, are there predefined handles which can be used to get the
> standard input, standard or standard error files?
>
> If they are not predefined, how I can create them?
>
> Best regards,
>
> Adriano.
You can do this:
my $FH = *STDOUT;
print $FH "Hello World\n";
which creates an ALIAS for STDIN, so if you later redirect the
STDOUT somewhere the $FH will "get redirected" too:
#!perl
use FileHandle;
$FH = *STDOUT;
print $FH "Hello World\n";
open STDOUT, '>c:\temp\zkOUT.txt';
print STDOUT "This goes to STDOUT\n";
print $FH "And this goes to \$FH\n";
__END__
As you can see both the "this goes to ..." messages end up in the
file.
Or you can use :
open $FH, '>&STDOUT';
which dup()s the filehandle so that even if you change where
STDOUT points to, the $FH will still write to the original
file/device/pipe.
#!perl
use FileHandle;
open $FH, '>&STDOUT';
print $FH "Hello World\n";
open STDOUT, '>c:\temp\zkOUT.txt';
print STDOUT "This goes to STDOUT\n";
print $FH "And this goes to \$FH\n";
__END__
HTH, Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]