At 14.16 1998.02.13, Mark Manning/Muniz Eng. wrote: >According to Chris Nandor: >> >> This is not really a MacPerl issue, but I need to correct some >> misinformation here. local() variables are global. my() variables are >> lexical (local, not local()). A local() variable simply saves the value of >> a global variable, and restores that value to that variable when the >> dynamic scope of the local() variable exits. >> > >Well, sorry too but you've presented some misinformation now also. > >>From the Perl Man pages, the LOCAL command: > > local(LIST) > Declares the listed variables to be local to the > enclosing block, subroutine, eval or "do". All the > listed elements must be legal lvalues. This > operator works by saving the current values of those > variables in LIST on a hidden stack and restoring > them upon exiting the block, subroutine or eval. > This means that called subroutines can also > reference the local variable, but not the global > one. The LIST may be assigned to if desired, which > allows you to initialize your local variables. (If > no initializer is given for a particular variable, > it is created with an undefined value.) Commonly > this is used to name the parameters to a subroutine. > >Which means the local command only makes the variables >global to those routines which are contained with the >routine which created them. Not global to all programs. > >The rest though is accurate. :-) Thanks for posting! I said nothing inaccurate or wrong. There is no such thing as "global to a routine." Global is global. The wording there is bad, and old. It looks like perl 4; the perl 5 docs reference my() and point to perlsub for a more in-depth explanation. A local() is global in every sense of the word. #=== perlfunc.pod local EXPR A local modifies the listed variables to be local to the enclosing block, subroutine, eval{}, or do. If more than one value is listed, the list must be placed in parentheses. See the section on Temporary Values via local() in the perlsub manpage for details. But you really probably want to be using my() instead, because local() isn't what most people think of as "local"). See the section on Private Variables via my() in the perlsub manpage for details. #=== perlsub.pod 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. #=== example #!perl -w $a = 1; a(); { local($a) = 2; a(); } a(); sub a {print $main::a} Returns: 121 -- 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