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

Re: declare/initialize variables at bottom of script?

by Laurent_R (Abbot)
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038353]
[Lady_Aleena]: marioroy, the find worked fine at the command line.
[marioroy]: LA, yeah. than there's no reason why it cannot work inside qx. But chatting is hard in PM. I cannot see the code now.
[shmem]: Lady_Aleena: sometimes a quick glance isn't enough.
[Lady_Aleena]: What?! Can't stat ~/Music: No such file or directory? The ~/ doesn't expand?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-04-23 21:00 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.