Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: perl global vars in subroutines

by coreolyn (Parson)
on Feb 16, 2004 at 18:09 UTC ( [id://329401]=note: print w/replies, xml ) Need Help??


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%

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://329401]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found