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]