Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

(RhetTbull) Re: Redefining print

by RhetTbull (Curate)
on Feb 08, 2002 at 19:12 UTC ( #144189=note: print w/replies, xml ) Need Help??

in reply to Redefining print

Unfortunately I think print is one of the built-ins that can't be overloaded (though I don't recall where I read this). You don't state why you want to overload it but you can probably accomplish what you want using Filter::Handle to intercept output to filehandles (including STDOUT and STDERR).

For example, the following snippet is pulled from one of my programs. The filter sub does 2 things: 1. if it sees any text that matches a password, it replaces it with xxxxx (that means I can dump config info to a log file for debugging but not worry about sensitive data being strewn about) and 2. It prints a copy of everything sent to STDOUT and STDERR to a log file.

use Filter::Handle qw(subs); Filter \*STDOUT, \&filter_sub; Filter \*STDERR, \&filter_sub; sub filter_sub { #sub for Filter::Handle #filter out the password if we see it so password doesn't get stre +wn all over log files local $_ = "@_"; my $pass = $config{password}; s/$pass/xxxxx/g; #write everything to logfile then to pass to filtered file handle print LOGFILE $_; $_; }

Replies are listed 'Best First'.
Re: Re: Redefining print
by blakem (Monsignor) on Feb 08, 2002 at 19:45 UTC
Re(2): Redefining print
by suaveant (Parson) on Feb 08, 2002 at 19:44 UTC
    Ahhh... actually, you just made me realize that the most likely problem is coming from the data I print through a UNIX socket... and can probably confiscate that data easily. I am actually trying to track down a confusing "Premature end of script headers"

                    - Ant
                    - Some of my best work - (1 2 3)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://144189]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2021-02-26 13:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found