home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5286 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  1.6 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Local variable assignment bug in 4.035?
  5. Message-ID: <1992Aug12.231738.23823@netlabs.com>
  6. Date: 12 Aug 92 23:17:38 GMT
  7. References: <1992Aug11.025222.26759@athena.mit.edu> <1992Aug11.171836.20143@reed.edu>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 36
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <1992Aug11.171836.20143@reed.edu> mjeffery@reed.edu (Mark Jefferys) writes:
  14. : In article <1992Aug11.025222.26759@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes:
  15. : _% $num = 5;
  16. : _% 
  17. : _% &foo($num);
  18. : _% sub foo {
  19. : _%     local($num);
  20. : _% 
  21. : _%     ($num) = @_;
  22. : _% 
  23. : _%     print "foo: $num\n";
  24. : _% }
  25. : _% foo:
  26. : Maybe Larry can tell us whether this is [will be treated as] a bug or
  27. : a feature.
  28.  
  29. Perl 5 will handle this by introducing static scoping of some sort or
  30. other.  Perl 4 handles this by blessing only the "local($num) = @_"
  31. form for use by anyone who doesn't understand dynamic scoping.
  32. Assignment to a local() takes specific pains to copy the value of the
  33. right-hand side before localizing the variables on the left.  This
  34. is the sense in which "variable suicide" was fixed.  It has not
  35. been fixed in any other sense--the general way to fix dynamic scoping
  36. is with static scoping.
  37.  
  38. Just to satisfy your curiosity, I suspect that static scoping will
  39. be done with "my":
  40.  
  41.     my($arg1,$arg2) = @_;    # list context for right-hand side
  42.     my $foo = <>;        # scalar context for right-hand side!
  43.  
  44. Larry
  45.