From:   "Paul Murphy" <[EMAIL PROTECTED]>

> Is there a particular way I have to implement this?  I have the
> following code but it runs the normal getproto rather than my one.
> 
> --------------------------------------
> #/bin/perl -w
> 

You have to put a BEGIN{} block around the subroutine definition 
and "instalation:

        BEGIN {

                sub my_getprotobyname {
                        print "hello\n";
                }
                *CORE::GLOBAL::getprotobyname = \&my_getprotobyname;
        }

        print "Going to function\n";

        my @test = getprotobyname("tcp");
        print @test;

Sorry I forgot about that before (I've always did things like this in a 
module's import() function which is called within execution of use 
statements which means it behaves kind of as if it was in a 
BEGIN{} block.)

The reason is ... you have to replace the function BEFORE perl 
parses and compiles the calls to it.

I guess it would be best to put the functions into a module and 
replace the core functions in an import :


        package Fake::Getprotos;
        
        sub my_getprotobyname {
                print "hello\n";
        }

        ...

        sub import {
                *CORE::GLOBAL::getprotobyname 
                        = \&my_getprotobyname;
                ...
        }

        1;

Just make sure that module is the first to be used.

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

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to