Jenda,
Thanks for the tip. I'm posting to let the archives and others know about 
this nifty feature.

I eventually solved my problem by using Filter::Handle somewhat thusly:

package main;
use Filter::Handle 'subs';
Filter \*STDOUT, sub { map { uc } }
package ....

It works nicely. I've just coerced main's STDOUT through that anonymous 
subroutine. The return value is actually sent to STDOUT. My real problem 
was to capture the data going to STDOUT to a file without having to edit 
bunches of other routines that just use the normal print() call. I put 
that spot of code into a common library that is loaded at the beginning 
and so now I just patched the behaviour of *all* the STDOUT handles for 
all the scripts. ;-) This is just for debugging, of course.

Josh





"Jenda Krynicky" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
04/05/2002 08:57 AM

 
        To:     <[EMAIL PROTECTED]>
        cc: 
        Subject:        Re: Overriding CORE:: functions?


From: [EMAIL PROTECTED]

> I'd like to override standard functions like 'print' but I can't
> figure out how to do that. Ideas? I've included a sample of how I
> *expected* the code to work where a print in main would really be
> &main::print() which is free to call (or not) &CORE::print(). What do
> I need to do to make the first normal print call work like the second
> qualified call and the third normal print call? You'll notice how the
> first print() call uses CORE::print while the second print() uses
> main::print().
> 
> Confused,
> Josh

print() is more magical than just about anything else.
And it's actualy a method (of sorts, I will not go into details. I don't 
fully understand it myself. Though I can change its behaviour if I 
need to.)

I think you want to read
                 perldoc perltie 
                                 (about "Tying FileHandles")
                 perldoc Tie::Handle


The more normal functions may be overwritten like this :

                 sub mysin {
                                 print "called sin\n";
                 }

                 BEGIN {
                 *CORE::GLOBAL::sin = \&mysin;
                 }

                 sin(0.1);
                 package foo;
                 sin(0.1);

Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
  --- me
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to