Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: declare/initialize variables at bottom of script?

by Laurent_R (Canon)
on Jun 11, 2013 at 22:11 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1038353]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found