in reply to Re: Scope Between global and my
in thread Scope Between global and my

Ok, I can see how a lexical block can do this for contiguous code segments. But I see a possible future problem in keeping track of this. Not moving a sub out of the block, etc.

what I would really like is to be able to say. Ok, when I start sub-b from sub-a, I want to run sub-b in the same data space as sub-a.

Replies are listed 'Best First'.
Re: Re: Re: Scope Between global and my
by davido (Cardinal) on Apr 01, 2004 at 18:11 UTC
    Then you probably want to use packages to segregate namespace.

    Honestly, if maintainability is an issue, and you are afraid that a lexical block enclosing a couple of subs is going to turn out to be a nightmare to keep track of, you're reached that point where packages and modules are there help you keep it all straight.


    Dave

      You may be right. This is actually already in a module, so I may need to split it into a sub module. Believe it or not, I am trying not to be too fancy because I am a perl novice.

      local seems to be doing the trick, but I have to turn off strict to use it and that makes me uncomfortable. Thanks

        Don't turn off strict; use vars qw/variable names/;


        Dave

        You don't have to turn off strict if you either
        a) package-qualify the variable name, as in my previous example; or
        b) declare the variable using our or use vars.

        our is supposed to be a more modern replacement for use vars, but they don't do exactly the same thing, so which one is most appropriate really depends on your specific circumstances.

        jdporter
        The 6th Rule of Perl Club is -- There is no Rule #6.