T
Todd
I meet with a inconsistent behavior about the type glob reference
blow. Here Case3 works fine. But Case1 and Case2 file a compile error.
The difference between Case2 and Case3 is that I move the typeglob
assignment from inside SCOPE to outside SCOPE. I'm trying to
understand this, may you help me?
Case1:
#! /bin/perl -l
BEGIN {
package Foo;
sub foo { print "foo called"; }
$main::{foo} = \&foo;
}
&main::foo();
__END__
Undefined subroutine &main::foo called at - line 9.
Case2:
#! /bin/perl -l
BEGIN {
package Foo;
sub foo { print "foo called"; }
$main::{foo} = \&Foo::foo;
}
&main::foo();
__END__
Undefined subroutine &main::foo called at - line 9.
Case3:
#! /bin/perl -l
BEGIN {
package Foo;
sub foo { print "foo called"; }
}
$main::{foo} = \&Foo::foo;
&main::foo();
__END__
foo called
Thanks,
Todd
blow. Here Case3 works fine. But Case1 and Case2 file a compile error.
The difference between Case2 and Case3 is that I move the typeglob
assignment from inside SCOPE to outside SCOPE. I'm trying to
understand this, may you help me?
Case1:
#! /bin/perl -l
BEGIN {
package Foo;
sub foo { print "foo called"; }
$main::{foo} = \&foo;
}
&main::foo();
__END__
Undefined subroutine &main::foo called at - line 9.
Case2:
#! /bin/perl -l
BEGIN {
package Foo;
sub foo { print "foo called"; }
$main::{foo} = \&Foo::foo;
}
&main::foo();
__END__
Undefined subroutine &main::foo called at - line 9.
Case3:
#! /bin/perl -l
BEGIN {
package Foo;
sub foo { print "foo called"; }
}
$main::{foo} = \&Foo::foo;
&main::foo();
__END__
foo called
Thanks,
Todd