Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re (tilly) 3: overloading the print function (or alternatives)

by tilly (Archbishop)
on Dec 04, 2000 at 23:57 UTC ( [id://44844]=note: print w/replies, xml ) Need Help??


in reply to Re: Re (tilly) 1: overloading the print function (or alternatives)
in thread overloading the print function (or alternatives)

Then you would mess up someone who had inserted:
print STDERR "Called node 'foo'\n";
as a debugging aid. (The messsage should show up in your webserver's logs.) The following (untested) code is much nicer:
package noprint; use Carp; sub PRINT { my $msg = Carp::longmess("You must return rather than print"); print "Content-type: text/plain\n\n$msg"; die $msg; } *PRINTF = *PRINT; sub TIEHANDLE { return bless ({}, shift); }
and elsewhere in the code:
tie(*NOPRINT, 'noprint'); select(NOPRINT); # time passes while the page is built. # Before spitting out the final page: select(STDOUT);
That catches the newbie error. Without the potential for headaches that overriding print causes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2025-07-11 02:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.