[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] defining variables if not already defined



At 16:14 -0700 2000.07.24, Tom Sackett wrote:
>I'm having a problem with the following code:
>
>   my ($var) = "bongo";
>   print "The variable is: $var\n";
>   my ($var) = "conga" unless (defined($var));
>   print "The variable is now: $var\n";

The my() operation is done at compile time, so is done regardless of the
condition.  Do the above code with -w and you get:

# "my" variable $var masks earlier declaration in same scope.

You have no reason to use my() a second time.  All my() means is that "this
variable has been declared for this block".  So once it has been declared,
it doesn't need to be done again.

   my($var) = "bongo";
   $var = "conga" unless defined $var;

-- 
Chris Nandor       |     pudge@pobox.com      |     http://pudge.net/
Andover.Net        | chris.nandor@andover.net | http://slashcode.com/

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org