Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

(RhetTbull) Re: Redefining print

by RhetTbull (Curate)
on Feb 08, 2002 at 19:12 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-29 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found