RE: Localizing variables

2002-11-05 Thread Jason Frisvold
That is exactly what I was hoping...

Thanks!

On Tue, 2002-11-05 at 16:48, Nikola Janceski wrote:
> the second 'my $var2' will have memory allocated to it, but will not be
> freed until Perl ends, but Perl will re-use that memory allocation after
> leaving the {BLOCK}.

-- 
---
Jason 'XenoPhage' Frisvold
Senior ATM Engineer
Penteledata Engineering
[EMAIL PROTECTED]
RedHat Certified - RHCE # 807302349405893
---
"Something mysterious is formed, born in the silent void. Waiting alone
and unmoving, it is at once still and yet in constant motion. It is the
source of all programs. I do not know its name, so I will call it the
Tao of Programming."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Localizing variables

2002-11-05 Thread Nikola Janceski
the second 'my $var2' will have memory allocated to it, but will not be
freed until Perl ends, but Perl will re-use that memory allocation after
leaving the {BLOCK}.


> -Original Message-
> From: Jason Frisvold [mailto:friz@;corp.ptd.net]
> Sent: Tuesday, November 05, 2002 4:43 PM
> To: [EMAIL PROTECTED]
> Subject: Localizing variables
> 
> 
> I'm curious if there are any side effects to doing the following :
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> my $var1 = "test1";
> my $var2 = "this is not test2";
> 
> {
>  my $var2 = "test2";
>  print "$var1 - $var2\n";
> }
> 
> print "$var1 - $var2\n";
> 
> 
> What I'm trying to do is create a temporary variable within the main
> body of the program.  I don't want that variable to stick 
> around after I
> use it (which is directly after I declare it) ...
> 
> In most cases, I'll be using "unique" variable names within that local
> block.  The idea is that I want to release the memory associated with
> those local variables without carrying them around.  The rest of the
> program definitely uses a lot more memory, but good memory management
> dictates that I release it when I'm done with it.  I never need that
> inner $var2 again, so why bother leaving it around?
> 
> 
> -- 
> ---
> Jason 'XenoPhage' Frisvold
> Senior ATM Engineer
> Penteledata Engineering
> [EMAIL PROTECTED]
> RedHat Certified - RHCE # 807302349405893
> ---
> "Something mysterious is formed, born in the silent void. 
> Waiting alone
> and unmoving, it is at once still and yet in constant motion. 
> It is the
> source of all programs. I do not know its name, so I will call it the
> Tao of Programming."
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Localizing variables

2002-11-05 Thread Jenda Krynicky
From: Jason Frisvold <[EMAIL PROTECTED]>
> I'm curious if there are any side effects to doing the following :
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> my $var1 = "test1";
> my $var2 = "this is not test2";
> 
> {
>  my $var2 = "test2";
>  print "$var1 - $var2\n";
> }
> 
> print "$var1 - $var2\n";
> 
> 
> What I'm trying to do is create a temporary variable within the main
> body of the program.  I don't want that variable to stick around after
> I use it (which is directly after I declare it) ...

Aplaud everybody! :-)

Yes, this is IMO the best way to do this.
Restrict the variables as much as you can.

There is only one case when you have to be carefull. If you define a 
procedure within the same block you efectively create a closure, the 
procedure will have it's own copy of the variable. Which may be what 
you want, but you should be aware of that.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]