Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: declare/initialize variables at bottom of script?

by Laurent_R (Vicar)
on Jun 11, 2013 at 22:11 UTC ( #1038353=note: print w/ replies, xml ) Need Help??


in reply to declare/initialize variables at bottom of script?

I ... usually declare/initialize variables at the top of a script.

Don't do that. It is a bad idea.

I was also doing that at my beginning in Perl, because of my C background (I think it has changed in C, but there was a time where all variables had to be declared either at the beginning of each function, or at the beginning of the program for global variables.

Declaring all your variables at the beginning of the program defeats at least a good half of the advantages of lexical variables. It makes your variable essentially global, which is precisely what you don't want to do. You should rather declare your variables in the smallest possible lexical scope (function level, loop level, block level, whatever).


Comment on Re: declare/initialize variables at bottom of script?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-08-23 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (174 votes), past polls