I/O redirection works basically by localizing typeglobs that
describe file handles. In the first example
STDOUT is redirected to an output file:
sub ...
{
local( *STDOUT);
open( F, '>/tmp/x');
*STDOUT = *F;
print "hello world \n";
close(F);
}
The following code shows how STDOUT is redirected to
a text widget (by J. Medved):
my $w_text = $top->Scrolled( 'Text',
-relief => 'sunken',
-setgrid => 'true',
-height => '30'
-scrollbars => 'e')->pack();
sub ...
{
local( *STDOUT);
tie( *STDOUT, 'Tk::Text', $w_text);
open(NET, "ls -al |");
while (<NET>)
{
print "$_";
}
close( NET);
}