Script:
use strict;
my $bar = tie(*STDOUT, 'Bar');
print "Before\n";
test();
print "After\n";
untie(*STDOUT);
sub test {
local(*STDOUT);
my $foo = tie(*STDOUT, 'Foo');
print "In medias res\n";
untie(*STDOUT);
}
package Foo;
sub TIEHANDLE {
my ($class) = @_;
return bless({},$class);
}
sub PRINT {
my ($self) = shift;
print STDERR ("Foo::PRINT: ",@_);
}
package Bar;
sub TIEHANDLE {
my ($class) = @_;
return bless({},$class);
}
sub PRINT {
my ($self) = shift;
print STDERR ("Bar::PRINT: ",@_);
}
Output:
Bar::PRINT: Before Foo::PRINT: In medias res AfterExpected output:
Bar::PRINT: Before Foo::PRINT: In medias res Bar::After
It seems like STDOUT is retied to Foo and then untied. local(*STDOUT) has no effect here. Why?
In reply to Re: (tye)Re: Local tied FILEHANDLE
by gildir
in thread Local tied FILEHANDLE
by gildir
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |