develooper Front page | perl.beginners | Postings from February 2002

re: No access to /etc/protocols

Thread Previous | Thread Next
Jenda Krynicky
February 27, 2002 06:12
re: No access to /etc/protocols
Message ID:
From:   "Paul Murphy" <>

> 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:


		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 {
			= \&my_getprotobyname;


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


=========== == ==========
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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About