use strict: why? 
Author Message
 use strict: why?

[A complimentary Cc of this posting was sent to Uri Guttman

> you are missing the point. in your mind, separate the way you access a
> value (lexical or symbolic) from the value itself. local affects the
> value only and not the variable. so if you have access to the value you
> can localize it. a slice has access to the values of a lexical so local
> can work on those values.

Recently, I finally understood why there is some opposition in allowing
local() to work on lexical variables.  Here is how access to
symbol-table variable is performed:

  a pointer to a glob (stored in the code tree)         ====>    (0)
  SV structure of a glob (has a pointer to ...)         ====>    (1)
  XPVGV structure of a glob (has a pointer to ...)      ====>    (A)
  a table consisting of pointers to a scalar, array etc ====>         (B)
  a pointer to a scalar                                 ====>         (C)
  SV structure (containing a pointer to a table which
                decribes the value of the variable)     ====>         (D)

local *var changes the pointer used on the step "A" of the
translation, local $var changes the pointer used on the step "C".
Note that there is another way to change the value of the variable, it
is overwriting the info used on the step "D".

Lexicals are accessed differently:

  an offset (stored in the code tree)                     ====>    (0)
  an entry in the "scratchpad" table of the current scope ====>    (C)
  [the rest is the same]

(this entry is alread a pointer to a scalar).  Again, to local()ize
the value, you can either change the entry used on the step "C", or
change the SV structure (step "D").  Complications:

  a) localizing-via-step "D" would make the semantic of existing
     references to localized variables different:

       $var = 3;
       $ref = \$var;
       local $var = 11;
       print $$ref;

  b) On the other hand, there is some code which assumes that
     variables having a flag IsALexicalVar may be accessed from the
     scratchpad.  Thus localizing-via-step-C, in other words,
     modifying the scratchpad to have a pointer to a completely new
     variable, may confuse Perl;

  c) Anyway, localizing conflicts with clearing of lexical at the end
     of the scope - in which order the things should be
     de-localization/clearing be done?


Fri, 28 Feb 2003 12:34:05 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Assigning Null to a TStringField ?

2. Why, why, why, -w and use strict?

3. Why use strict?

4. works without strict but not with why ????

5. why not use(strict)?

6. why does strict not warn about shaddowing declarations ?

7. List of DBE Error codes..

8. deleting from a bst

9. Paradox OLE FieldType Help

10. RTE 200 and upgrade questions

11. TPW - wincrt menu problem


Powered by phpBB® Forum Software