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

In reply to Tie *STDOUT, recursion error by Superfox il Volpone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.