Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: declare/initialize variables at bottom of script?

by Laurent_R (Parson)
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 meditating upon the Monastery: (12)
As of 2014-09-16 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (49 votes), past polls