home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!europa.asd.contel.com!awds.imsd.contel.com!news.cerf.net!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: Bug with foreach/local in 4.035
- Message-ID: <1992Dec31.210225.26222@netlabs.com>
- Date: 31 Dec 92 21:02:25 GMT
- References: <SOUP.92Dec28105043@ampersand.ampersand.com> <1992Dec29.224047.20472@news.eng.convex.com>
- Sender: news@netlabs.com
- Distribution: comp
- Organization: NetLabs, Inc.
- Lines: 31
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <1992Dec29.224047.20472@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
- : From the keyboard of soup@ampersand.com (Doug Campbell):
- : :There appears to be a bug (or at least a surprising behavior) in 4.035
- : :regarding foreach and local. It seems that a construct like:
- : :
- : : foreach $i (@list)
- : :
- : :will cause a subsequent (down the call stack) "local ($i)" to cause the
- : :item in @list currently referenced by $i to appear blank.
- :
- : That's a manifestation of "variable suicide". You can read about it
- : in the FAQ.
-
- This works right in Perl 5, because local saves the scalar pointer
- rather than the scalar value. On top of this, you'll probably use
- "my" rather than "local", which will be immune to all the problems of
- dynamic scoping.
-
- An interesting question is whether the implicit dynamic scoping of the loop
- variable should change to lexical scoping. I don't think it should, for
- two reasons. It would be unclear how far the scope of the variable extends,
- and it would break some existing scripts.
-
- Hmm. The way things work, it might be possible to force lexical scoping
- with
-
- for my $i (1..10)
-
- Hmm. Hafta think about that...
-
- Larry
-