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]

Reply via email to