R
Raymundo
Hi all,
I wrote a file that contains two packages:
----------------------------
#!/usr/bin/perl
use strict;
use warnings;
# "main" package, implicitly
sub foo {
print "sub foo in main\n";
}
our $foo = "scalar foo in main";
foo(); # no problem
print "$foo\n"; # no problem
# "Test" package begins here
package Test;
foo(); # This is an error, because this calls
"&Test::foo()" that doesn't exist
----------------------------
The last "foo();" results in an error, as you know, because "&foo"
exists in "main", not in "Test". It should be "main::foo();".
Ok, then... here is my question...
----------------------------
# (omit the same code as above)
# "Test" package begins here
package Test;
print "$foo\n"; # I think this is an error, too.
----------------------------
Execution result:
sub foo in main
scalar foo in main
scalar foo in main -- $main::foo is printed...
I thought that the last line would result in an error (just like the
above case).
And I thought it would, if "use strict" is ignored in the scope of
"Test", print null string (the value of $Test::foo).
But the last line printed the value of "$main::foo" variable...
I can't understand this.. Any help would be apprecieated.
I wrote a file that contains two packages:
----------------------------
#!/usr/bin/perl
use strict;
use warnings;
# "main" package, implicitly
sub foo {
print "sub foo in main\n";
}
our $foo = "scalar foo in main";
foo(); # no problem
print "$foo\n"; # no problem
# "Test" package begins here
package Test;
foo(); # This is an error, because this calls
"&Test::foo()" that doesn't exist
----------------------------
The last "foo();" results in an error, as you know, because "&foo"
exists in "main", not in "Test". It should be "main::foo();".
Ok, then... here is my question...
----------------------------
# (omit the same code as above)
# "Test" package begins here
package Test;
print "$foo\n"; # I think this is an error, too.
----------------------------
Execution result:
sub foo in main
scalar foo in main
scalar foo in main -- $main::foo is printed...
I thought that the last line would result in an error (just like the
above case).
And I thought it would, if "use strict" is ignored in the scope of
"Test", print null string (the value of $Test::foo).
But the last line printed the value of "$main::foo" variable...
I can't understand this.. Any help would be apprecieated.