At 15.24 1998.02.13, Mark Manning/Muniz Eng. wrote: >And just for the record: > >muldar[22]{/tmp_mnt/disk4/mark/perl}(14:07) >/usr/local/bin/perl -v > >This is perl, version 5.004_04 built for IP22-irix > >In case you want to say I'm running perl 4. The output for this program is: No, the DOCS you quoted appear to be perl 4. Certainly, they are not perl 5.004. >Main : myVar = Main Routine >mySub : myVar = First Subroutine! >mySub2 : myVar = Second Subroutine! >mySub3 : myVar = Second Subroutine! >mySub2 : myVar = Second Subroutine! >mySub : myVar = First Subroutine! >Main : myVar = Main Routine > >Which, as you can see, myVar's original value is kept for >the main program. The second version of myVar (ie: >Subroutine #1) changes the value of myVar to "First >Subroutine!". The second subroutine changes myVar to >"Second Subroutine!". The third subroutine only prints the >value of myVar. Which shows it is global to the third >subroutine. Then, as everything pops back out the value of >myVar is reloaded from the hidden stack. You are using bad terminology. A global is a global is a global. Putting local() on it does not change that. All it does is temporarily change the value of that global variable for the duration of the dynamic scope of the enclosing block. >You have said it yourself. "A local modifies the listed >variables to be local to the enclosing block" A block is >defined as everything contained within a given subroutine >or "{}" area. Thus, the LOCAL command defines a local (as >per your last posting). But the statement "local() >variables are global" was incorrect. No, it is not. I have gone over this many times with Tom Christiansen, and if you like, I can show you my IRC logs and notes. But I think I can prove it. I thought I already did, but here goes: #!perl package Foo; sub foo {print $main::bar} package main; $bar = 1; Foo::foo(); { local($bar) = 2; Foo::foo(); } Foo::foo(); Returns: 121 What is not global about local($bar)? A subroutine that is outside of its lexical scope AND in a different package accessed it and printed its value. Then the dynamic scope ended, and the variable's value was restored to what it previously was. >I just felt that saying a variable >defined as LOCAL was in fact GLOBAL was misleading to the >original poster and possibly others. But it is true. >Further, if there are no subprograms beneath the called >subroutine (ie: As in my example with a subroutine being >called from inside of another subroutine), the LOCAL >statement really does cause a variable to be local with >regards to the rest of the program. I think you are confused when you use the word "local". When used as in global vs. local, local means lexical. And local() has nothing to do with lexical. A local() variable is a package variable, as my above script proves. local() == global == package == dynamic my() == local == lexical lexical means that it can be accessed from only within a particular lexical scope, which is a block, eval, or file. global means it can be accessed from ANYWHERE. As I have shown several times, local variables are accessible from anywhere, and hence are globals. Again, from perlsub, which I just quoted last time: "A local() modifies its listed variables to be local to the enclosing block, (or subroutine, eval{}, or do) and any called from within that block. A local() _just gives temporary values to global (meaning package) variables_. This is known as dynamic scoping. Lexical scoping is done with "my", which works more like C's auto declarations." perlsub says it right there: local() gives temp values to global variables. local()ized vars are still global. They have always been global. They can have a value that is only valid for a particular dynamic scope, but that has nothing to do with its global nature. If you are still confused, please e-mail me privately. -- Chris Nandor mailto:pudge@pobox.com http://pudge.net/ %PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6']) #== New Book: MacPerl: Power and Ease ==# #== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==# ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch