in reply to perl global vars in subroutines

This is a kludge answer in comparison to the other more esteemed monks, but I've gotten into the habit of utilizing enviornmental vars (i.e $ENV{'VAR'} )for my globals.

Replies are listed 'Best First'.
Re: Re: perl global vars in subroutines
by CountZero (Bishop) on Feb 16, 2004 at 20:44 UTC
    Interesting idea, to say the least.

    But wouldn't it get terribly mixed up if your script was run more than once at the same time? And don't you have to "clean up" the environment variables when you end your code? What happens if your code --heaven forbid-- crashes halfway through before you can clean the envoironment? Is there a way to reset the environment to its pristine state?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      I only use in non-parallel processed code. As for the ENV itself, when the shell dies the vars die, only code within the created fork and below contain the values.

        I don't know what you're saying, but perl only affects perl, so the enviroment which started perl does not get modified by perl
        E:\>echo %FORK% %FORK% E:\>perl -le"$ENV{FORK}=666;" E:\>echo %FORK% %FORK%