in reply to perl global vars in subroutines

use our
our global_1; our global_2; require(perl_mod.pm);
now in your perl_mod.pm you need to include:
our global_1; our global_2;
This will allow you to use global variables across perl files. Make sure you use Strict as well.

Replies are listed 'Best First'.
Re: Re: perl global vars in subroutines
by tilly (Archbishop) on Feb 16, 2004 at 17:17 UTC
    As I said a long time ago, Why is 'our' good?

    I've yet to see a good answer to that question.

    (The original question is a sign of someone rapidly digging himself a deep, nasty hole. But I'll let someone else decide whether to write up a rant on modularity.)

Re: perl global vars in subroutines
by Abigail-II (Bishop) on Feb 16, 2004 at 17:32 UTC
    Well, first of all, if the perlmod.pm file starts with package Me;, it's not going to work. The our $global_1; in the main file will refer to $main::global_1;, while the our $global_2; in the module refer to $Me::global_1;.

    But if you don't use a package statement, and have everything in the main package, and you aren't using parameters to pass arguments to subroutines, there's little reason to use strict and our.

    Abigail