Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

(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 $_; $_; }


Comment on (RhetTbull) Re: Redefining print
Download Code
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)

Re: Re: Redefining print
by blakem (Monsignor) on Feb 08, 2002 at 19:45 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-07-29 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (220 votes), past polls