Hi Uri,

Not sure if it was because I've been dealing with mainly web servers for the 
past few years, but I always read your name as U-R-I instead of Uri. :-) It 
looks like you've got a name that's relevant to your profession, most of us 
didn't have that fortune!

On Thursday 13 May 2010, Uri Guttman wrote:
> 
> there are two ways to declare (not define) a hash at a file scope (which
> is what you are calling main part). my declares it lexically to the file
> which is decent if needed. our declares it as a package global which
> means it can be accessed from any code using the fully qualified name or
> it can be exported too. both have their uses. but using globals in
> general is not a good idea if you can avoid it. the issues are well know
> and include action at a distance (some other code can modify your hash
> and you won't know why/where/what about it). passing data is safer
> because it isolates the data to the code that needs it.
> 
> isolation is a major coding philosophy all coders need to
> learn. isolated code means you can test more easily (no side effects or
> outside code to worry about). you can replace isolated code easily as it
> isn't intertwined with other code and data. 
> 

Your explanation is much appreciated. So in general, we should make the 
variables as least visible as we can. In that case, I don't think we should 
cover much code at the file scope. The code at the file scope should be moved 
to a lexical scope through a subroutine for more elegance. Correct?

>   APK> 3) Also, am I correct in guessing that the memory that's used to
>   APK> allocate a variable defined with 'my' will be freed up once the
>   APK> current lexical scope is exited?
> 
> true but with a file lexical (or global) that won't happen until the
> program exits. this is another reason to declare things in the tightest
> scope possible. also note that the memory is freed up for perl to reuse,
> not for the OS. it will mean perl won't need to grow its size if it can
> reuse lexical data that is reclaimed upon scope exit.
> 

Doesn't Perl free up any memory that was used by it until the program exits? If 
that's how it goes, if a Perl program uses a lot of memory at the beginning and 
it takes lots of time for the program to finish up, all those memory space are 
being wasted, no?

-- 
Regards,
Akhthar Parvez K
http://Tips.SysAdminGUIDE.COM
UNIX is basically a simple operating system, but you have to be a genius to 
understand the simplicity - Dennie Richie

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to