Re: Is this possible to override print() ?
- From: chas.owens@xxxxxxxxx (Chas. Owens)
- Date: Mon, 25 Feb 2008 23:32:48 -0500
On Mon, Feb 25, 2008 at 9:43 PM, Panda-X <exilepanda@xxxxxxxxx> wrote:
Sorry... the email is unfinished, the reason why I need to do this issnip
because
I don't want to pollute the existed codes / context ... the original print
statements would
like to retain, but I can still do the translations by adding :
use OverridePrint;
in a common module that all existed scripts are now using.
You can find out whether or not a core function can be overridden by
calling the prototype* function with that function's name prepended
with CORE::. If it returns a prototype, then you can override it, if
it returns undef, then you cannot. Unfortunately for you, print can
not be overriden (most likely because of its indirect object syntax
file handle wonkiness); however, there is another way: source filters.
You can use Filter::Simple to replace every call to print with a call
to my_print. Please note that it isn't quite that simple though. You
will need to correctly handle lines like
print $message;
print $log $message;
print STDERR "oops\n";
by converting them into something like
my_print(args => [$message]);
my_print(file => $log, args => [$message])
my_print(file => \*STDERR, args => ["oops\n"]);
and those were the simple cases.
* http://perldoc.perl.org/functions/prototype.html
** http://search.cpan.org/dist/Filter-Simple/lib/Filter/Simple.pm
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
.
- Follow-Ups:
- Re: Is this possible to override print() ?
- From: Jenda Krynicky
- Re: Is this possible to override print() ?
- References:
- Is this possible to override print() ?
- From: Panda-X
- Re: Is this possible to override print() ?
- From: Panda-X
- Is this possible to override print() ?
- Prev by Date: Re: scalar / hash problem in HTML::Parser
- Next by Date: Re: scalar / hash problem in HTML::Parser
- Previous by thread: Re: Is this possible to override print() ?
- Next by thread: Re: Is this possible to override print() ?
- Index(es):
Relevant Pages
|