fanasy has asked for the wisdom of the Perl Monks concerning the following question:
I can get the $testBegin::global but I cannot get the $testEnd::global
my question is that
it seems the test package definition location is the key for this issue.
how perl consider the different order ? why perl can call testEnd::show_me() in main but can't see the $testEnd::global in main ?
there is the code :
#!/usr/bin/perl use feature qw/say/; use Data::Dumper; package testBegin { $global = "I'm in the testBegin package global version"; sub show_me { print "$tag: testBegin package $global\n"; } } testBegin::show_me(); print "-"x60; print "\n"; testEnd::show_me(); package testEnd { $global = "I'm in the testEnd package global version"; sub show_me { print "$tag: testEnd package $global\n"; } }
output:
: testBegin package I'm in the testBegin package global version
------------------------------------------------------------
: testEnd package
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: why package definition order affect the available of package variable
by haukex (Archbishop) on Oct 20, 2019 at 10:16 UTC | |
by fanasy (Sexton) on Oct 20, 2019 at 14:03 UTC | |
|
Re: why package definition order affect the available of package variable
by rjt (Curate) on Oct 20, 2019 at 11:56 UTC | |
by fanasy (Sexton) on Oct 20, 2019 at 14:01 UTC | |
by rjt (Curate) on Oct 20, 2019 at 23:50 UTC | |
by fanasy (Sexton) on Oct 21, 2019 at 01:08 UTC |