On Feb 4, 7:13pm, Matthias Ulrich Neeracher wrote: } Subject: Re: [MacPerl] Problem with MacPerl 5.06 } schinder@pjstoaster.pg.md.us (Paul Schinder) writes: } >test.pl: } > } >#!/usr/local/bin/perl } >package test; } > } >#$a = "test"; } >#my $a = "test"; } >local $a = "test"; } > } >sub test {my $b = $a;return $b}; } >1; } > } >testmain.pl: } > } >#!/usr/local/bin/perl } > } >require "test.pl"; } > } >$a = test::test(); } >print "$test::a, $a\n"; } > } >Running testmain with the declaration line in test changed gives the following } > } > MacPerl 5.06 Sun Perl 5.001m } >$a: test, test test, test } >local $a: , , } >my $a: , , test } > } > } >The latter is what's been the problem with lwp5b6, because the authors } >universally declare variables "my" outside of routines, and MacPerl } >promptly forgets their existence and initial values. } } As others have pointed out, it is not so clear whether what you're doing is } really *supposed* to work. While conventional meaning of "lexical scoping" } would imply that it does, the Perl manpages focus on my() being defined only } for a single scope. However, the Perl5.0.2beta3 manpage gives an example which } hints that this is possible. I believe it should work in both versions. Larry's intent with my was (at least partially) to emulate what the typical C programmer would expect. Witness: http://www.metronet.com/perlinfo/perl5/perl5.MY.lvalue.info Since the variable $a is within the "containing block" of the package, it should be visible to all subroutines within that package, _as long as_ they dont declare their own version of $a. Here's a bit of C code to demonstrate the analogy. int main(){ int a = 1; /* a is scoped to main */ printf("a equals %d in main\n", a); foo(); bar(); baz(); } int a = 2; /* redeclare a outside scope of main */ void foo(){ printf("a equals %d in foo\n", a); } void bar(){ int a = 3; /* redeclare a for bar only */ printf("a equals %d in bar\n", a); } void baz(){ printf("a equals %d again in baz\n", a); } Which prints: a equals 1 in main a equals 2 in foo a equals 3 in bar a equals 2 again in baz And the equivalent perl code: package test; my $a = 2; sub foo{print "a is $a in foo\n"} sub bar{my $a = 3; print "a is $a in bar\n"} sub baz{print "a is $a again in baz\n"} package main; my $a = 1; print "a is $a in main\n"; test::foo(); test::bar(); test::baz(); } I'm not aware of having done any modifications to the standard perl source in } this area either. I'll have to look further into this issue. } I suspect Mac Bison. But I'm Cc'ing this to perl5-porters, just in case I've stuck my foot in my mouth again. } Matthias }-- End of excerpt from Matthias Ulrich Neeracher Bill