Here at work, my coworkers and I are maintaining a system which was written in perl 4 and partially converted to perl 5.004. We now run this code under perl 5.6. Surprise! scoping of variables is a major item of confusion when something needs to be fixed. So here is our lastest confusion, we ran into this occurence, and would be helped by some PM clarification.
We have a module with some global "my" variables. Ex: File: foo.pm
package foo; my $foo = 5; my $bar = 7; sub set_foobar { $foo = 6; $foo::bar = 8; }
Then we have a script that calls the subroutine "set_foobar". Ex: File: test.pl
use foo; print $foo::foo,"\n"; print $foo::bar,"\n"; foo::set_foobar(); print $foo::foo,"\n"; print $foo::bar,"\n";
Results:
Use of uninitialized value in print at test.pl line 6. Use of uninitialized value in print at test.pl line 7. Use of uninitialized value in print at test.pl line 13. 8
If "my" creates private variables, then what happens to this private variable when someone sets a value while stating its package name explicity. Why is it now available publicly?
Thanks
Dave
In reply to "my" variables going public? by DeaconBlues
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |