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

Re: [MacPerl][off topic] local & my (was Re:Any way to Tee...)



According to Chris Nandor:
<snip>
> 
> The terms I like (Tom Christiansen said it on IRC, and likely elsewhere) is
> "save and restore".  When you local() a variable, it is still the same
> variable as it was before (as evidenced with A::foo()) but it has a new
> temporary value, that reverts back to the original value at the end of the
> scope.

Yes!  :-)

The confusing part (to me) was the difference between:

	$myVar

	and

	$main::myVar

All global variables can be seen via the $main::<variable
name>.  Whereas truly local variables would be undefined.
When I re-read Chris' post (as I was busily typing away at
refuting his post) I saw the different manner in which he
referenced the variable and that was when I realized that I
was incorrect.

The real problem (as I see it) is that realistically, since
it is (as far as I know) impossible to jump out of a
subroutine without Perl automatically restoring the
localized variables it makes it (for all intents and
purposes) a local variable.  However, problems occur
because any routines which are below the routine containing
the local command also will see the modified value instead
of the original value.  The difference (as has been pointed
out repeatedly) is that IF the local command really made a
variable local THEN it would not show up in any subroutines
enclosed by the defining routine.  It would only truly be
local to the routine which created it.  Which is why the MY
command came into existence in the first place.  So Perl
could have a way of truly making a local variable.

For my part I'm now having to go back through some of the
routines I built in Perl 4.0 and make sure the local
commands are not causing problems because I thought that
the LOCAL command was truly local.  :-)

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch