Use the subs pragma:
use strict; use warnings; use subs qw/ open /; open(); sub open { print "Hello world!\n"; }
Here is an excerpt from the Camel book, Programming Perl
Overriding may be done only by importing the name from a module--ordinary predeclaration isn't good enough. To be perfectly forthcoming, it's the assignment of a code reference to a typeglob that triggers the override, as in *open = \&myopen. Furthermore, the assignment must occur in some other package; this makes accidental overriding through typeglob aliasing intentionally difficult. However, if you really want to do your own overriding, don't despair, because the subs pragma lets you predeclare subroutines via the import syntax, so those names then override the built-in ones:
I'm not going to address whether this is actually a good idea, other than to say you ought to really really really think about other options first, especially if you care about writing maintainable code.
Update: There's additional information on the subject in perlfaq7 and perlsub.
Dave
In reply to Re: design the open function
by davido
in thread design the open function
by singam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |