in reply to Having one sub routine point to another

In the general case, core functions can be overwritten by setting a reference in their slot in *CORE::GLOBAL at compile time. Then at runtime, when functions are called, the sub ref in that slot is used in place of the CORE:: function. (You almost never really want to do this, though.)

But, the problem here is of course that my and our aren't runtime functions. They are compile-time directives. If you are using a perl that is pre-our, and you try to map our->my (ignoring that they are very different things) you have a big problem: your fake our is called at runtime, after compile-time strict warnings are issued.

You can create an 'our()' subroutine, but it won't solve your problem: by the time it is called, it's too late. You need to intercept the source code before compile time (with a source filter, ick) or just suck it up and replace all the ours with use vars. You want that anyway, since replacing our with my is bound to break things badly, assuming the original use of our wasn't frivolous.

Replies are listed 'Best First'.
Re^2: Having one sub routine point to another
by cosmicperl (Chaplain) on Jul 04, 2005 at 04:20 UTC
    To get things straight in my head.

    At the moment my code declares some 'our' variables, some of which are in a BEGIN {} tag. It then uses VARS for each of those variables (I had to do this to stop strict from complaining) Later variables are defined with 'our' alone and strict doesn't complain (I guess it has something to do with the begin tag).

    Your telling me that if I go through my whole program and change every 'our' to 'my' and add the variable to the VARS list it'll be global even though it was declared with my? Or if it's in the VARS list do I not put a my in front?

    Sorry if I sound dense but it's 5:30am where I am and I've been working through the night (again).

    Thanks
    Lyle
    (Suspecting he may have to give up and update all his scripts)

      If it is in the use vars list, then do not put a my in front. You only need one or the other. You don't need to declare it other than in the use vars... just use it.

      When it is no longer 5:30 am, read up on perldoc -f my and perldoc -f our and pick which one you really want in each case.