Hi,
I was thinking to tie the *STDOUT handle to mask the values to be printed in the stardard output. Though, I hit a deep recursion error, probably because I lose the original reference to *STDOUT and invokes my new handle when trying to print:
package hyundai{
sub TIEHANDLE{
my $class = shift;
my $oldhandle = shift;
return bless ({"handle" => $oldhandle}, $class);
}
my $mask = sub{
(my $text = shift()) =~ s/a/b/g; # replaces a with b
return $text;
};
sub PRINT{
my $self = shift;
die("Not a ref") if !ref($self);
my $text = join('',@_);
print STDERR ("STDOUT: ", \*STDOUT, "\n"); # prints GLOB(0x880a20)
+
print STDERR ("STDERR: ", \*STDERR, "\n"); # prints GLOB(0x880a80)
print STDERR ("handle: ", \$self->{"handle"}, "\n"); # prints GLOB
+(0x8806c0)
$self->{"handle"}->print( &$mask($text) ); # infinite recursion !
}
};
print("Hello world 1 aaaaaaa\n");
my $oldhandle = *STDOUT;
undef(*STDOUT);
tie *STDOUT, "hyundai", $oldhandle;
print("Hello world 2 aaaaaaa\n");
I was following
this (old) post related to the same issue, though it does not seem that a working solution was proposed.
Any idea how to proceed ?
s.fox